close_drive:

If a drive has gone down and has dirty buffers associated with it,
  we'll get a panic when we try to vn_close it.  Check for this
  situation and discard any buffers; they're toast anyway.

  Only complain about usage count if DEBUG_WARNINGS is set.

check_drive:
  Change parameter name from drivename to devicename.

  Get the check for a referenced drive right.

  If the partition isn't a vinum drive, set the last error to ENODEV.

vinum_scandisk:
  Change parameter name from drivename [] to devicename [].
This commit is contained in:
Greg Lehey 1999-05-02 07:51:20 +00:00
parent 3041dc10ba
commit a2d8e114f4

View File

@ -215,12 +215,26 @@ close_drive(struct drive *drive)
{
if (drive->vp) {
LOCKDRIVE(drive); /* keep the daemon out */
/*
* If we can't access the drive, we can't flush
* the queues, which spec_close() will try to
* do. Get rid of them here first
*/
if (drive->state < drive_up) { /* we can't access the drive, */
vn_lock(drive->vp, LK_EXCLUSIVE | LK_RETRY, drive->p);
vinvalbuf(drive->vp, 0, NOCRED, drive->p, 0, 0);
VOP_UNLOCK(drive->vp, 0, drive->p);
}
vn_close(drive->vp, FREAD | FWRITE, NOCRED, drive->p);
if (drive->vp->v_usecount) /* XXX shouldn't happen */
#ifdef VINUMDEBUG
if ((debug & DEBUG_WARNINGS) /* want to hear about them */
&&(drive->vp->v_usecount)) /* XXX shouldn't happen */
log(LOG_WARNING,
"close_drive %s: use count still %d\n",
drive->devicename,
drive->vp->v_usecount);
#endif
drive->vp = NULL;
unlockdrive(drive);
}
@ -515,48 +529,49 @@ read_drive_label(struct drive *drive, int verbose)
* Return drive number.
*/
struct drive *
check_drive(char *drivename)
check_drive(char *devicename)
{
int driveno;
int i;
struct drive *drive;
driveno = find_drive_by_dev(drivename, 1); /* entry doesn't exist, create it */
driveno = find_drive_by_dev(devicename, 1); /* if entry doesn't exist, create it */
drive = &vinum_conf.drive[driveno]; /* and get a pointer */
if (read_drive_label(drive, 0) != DL_OURS) { /* not ours */
if (read_drive_label(drive, 0) == DL_OURS) { /* not ours */
for (i = 0; i < vinum_conf.drives_allocated; i++) { /* see if the name already exists */
if ((i != driveno) /* not this drive */
&&(DRIVE[i].state != drive_unallocated) /* and it's allocated */
&&(strcmp(DRIVE[i].label.name,
DRIVE[driveno].label.name) == 0)) { /* and it has the same name */
struct drive *mydrive = &DRIVE[i];
if (mydrive->devicename[0] == '/') { /* we know a device name for it */
/*
* set an error, but don't take the drive down:
* that would cause unneeded error messages.
*/
drive->lasterror = EEXIST;
break;
} else { /* it's just a place holder, */
int sdno;
for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { /* look at each subdisk */
if ((SD[sdno].driveno == i) /* it's pointing to this one, */
&&(SD[sdno].state != sd_unallocated)) { /* and it's a real subdisk */
SD[sdno].driveno = drive->driveno; /* point to the one we found */
update_sd_state(sdno); /* and update its state */
}
}
bzero(mydrive, sizeof(struct drive)); /* don't deallocate it, just remove it */
}
}
}
} else {
if (drive->lasterror == 0)
drive->lasterror = ENODEV;
set_drive_state(drive->driveno, drive_down, setstate_force);
}
for (i = 0; i < vinum_conf.drives_allocated; i++) { /* see if the name already exists */
if ((i != driveno) /* not this drive */
&&(DRIVE[i].state != drive_unallocated) /* and it's allocated */
&&(strcmp(DRIVE[i].label.name,
DRIVE[driveno].label.name) == 0)) { /* and it has the same name */
struct drive *mydrive = &DRIVE[i];
if (mydrive->devicename[0] == '/') { /* we know a device name for it */
/*
* set an error, but don't take the drive down:
* that would cause unneeded error messages.
*/
drive->lasterror = EEXIST;
break;
} else { /* it's just a place holder, */
int sdno;
for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { /* look at each subdisk */
if ((SD[sdno].driveno == driveno) /* it's pointing to this one, */
&&(SD[sdno].state != sd_unallocated)) { /* and it's a real subdisk */
SD[sdno].driveno = drive->driveno; /* point to the one we found */
update_sd_state(sdno); /* and update its state */
}
}
free_drive(mydrive);
}
}
}
return drive;
}
@ -920,7 +935,7 @@ initsd(int sdno)
/* Look at all disks on the system for vinum slices */
int
vinum_scandisk(char *drivename[], int drives)
vinum_scandisk(char *devicename[], int drives)
{
struct drive *volatile drive;
volatile int driveno;
@ -959,7 +974,7 @@ vinum_scandisk(char *drivename[], int drives)
snprintf(partname, /* /dev/sd0a */
DRIVENAMELEN,
"%s%c",
drivename[driveno],
devicename[driveno],
part);
drive = check_drive(partname); /* try to open it */
if ((drive->lasterror != 0) /* didn't work, */