1998-12-28 04:56:24 +00:00
|
|
|
|
/*-
|
|
|
|
|
* Copyright (c) 1997, 1998
|
|
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed under the so-called ``Berkeley
|
|
|
|
|
* License'':
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software developed by Nan Yang Computer
|
|
|
|
|
* Services Limited.
|
|
|
|
|
* 4. Neither the name of the Company nor the names of its contributors
|
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
1999-08-15 02:31:19 +00:00
|
|
|
|
*
|
1998-12-28 04:56:24 +00:00
|
|
|
|
* This software is provided ``as is'', and any express or implied
|
|
|
|
|
* warranties, including, but not limited to, the implied warranties of
|
|
|
|
|
* merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
|
* In no event shall the company or contributors be liable for any
|
|
|
|
|
* direct, indirect, incidental, special, exemplary, or consequential
|
|
|
|
|
* damages (including, but not limited to, procurement of substitute
|
|
|
|
|
* goods or services; loss of use, data, or profits; or business
|
|
|
|
|
* interruption) however caused and on any theory of liability, whether
|
|
|
|
|
* in contract, strict liability, or tort (including negligence or
|
|
|
|
|
* otherwise) arising in any way out of the use of this software, even if
|
|
|
|
|
* advised of the possibility of such damage.
|
|
|
|
|
*
|
2003-06-12 05:32:00 +00:00
|
|
|
|
* $Id: vinumio.c,v 1.39 2003/05/23 00:59:53 grog Exp grog $
|
1999-08-28 01:08:13 +00:00
|
|
|
|
* $FreeBSD$
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-01-23 01:29:05 +00:00
|
|
|
|
#include <dev/vinum/vinumhdr.h>
|
|
|
|
|
#include <dev/vinum/request.h>
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
1999-01-21 00:35:35 +00:00
|
|
|
|
static char *sappend(char *txt, char *s);
|
|
|
|
|
static int drivecmp(const void *va, const void *vb);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* Open the device associated with the drive, and
|
|
|
|
|
* set drive's vp. Return an error number.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
open_drive(struct drive *drive, struct thread *td, int verbose)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
2000-08-16 04:31:37 +00:00
|
|
|
|
struct cdevsw *dsw; /* pointer to cdevsw entry */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
2000-02-29 06:11:13 +00:00
|
|
|
|
if (drive->flags & VF_OPEN) /* open already, */
|
|
|
|
|
return EBUSY; /* don't do it again */
|
|
|
|
|
|
Finally make vinum ready for the root filesystem in FreeBSD 5.x. (A
similar patch has been in 4.x for a while, but is more hacky there.)
For this to work, vinum has to be loaded early (e. g. from
boot/loader), for obvious reasons. If the kernel env variable
(aka. loader variable) "vinum.autostart" is set, vinum then asks the
sysctl kern.disks for all available disks in the system, and scans
them for possible vinum headers.
For statically compiled kernels, this behaviour can be obtained even
without boot/loader by using "options VINUM_AUTOSTART" (though this is
not the recommended way).
Alternatively, the 4.x way to specify "vinum.drives" is also supported.
No further hacks (like the 4.x "vinum.root" variable) are needed,
since in 5.x, mountroot() asks back at the drivers to have them
resolve the name of the root FS into a dev_t (using the dev_clone
eventhandler).
(The MFC reminder below is for a partial MFC for vinum.autostart, the
rest is already there in 4.x.)
Timed out on: grog
MFC after: 2 weeks
2003-02-05 21:02:56 +00:00
|
|
|
|
drive->dev = getdiskbyname(drive->devicename);
|
|
|
|
|
if (drive->dev == NODEV) /* didn't find anything */
|
|
|
|
|
return ENOENT;
|
2000-02-29 06:11:13 +00:00
|
|
|
|
|
|
|
|
|
drive->dev->si_iosize_max = DFLTPHYS;
|
2000-08-16 04:31:37 +00:00
|
|
|
|
dsw = devsw(drive->dev);
|
Finally make vinum ready for the root filesystem in FreeBSD 5.x. (A
similar patch has been in 4.x for a while, but is more hacky there.)
For this to work, vinum has to be loaded early (e. g. from
boot/loader), for obvious reasons. If the kernel env variable
(aka. loader variable) "vinum.autostart" is set, vinum then asks the
sysctl kern.disks for all available disks in the system, and scans
them for possible vinum headers.
For statically compiled kernels, this behaviour can be obtained even
without boot/loader by using "options VINUM_AUTOSTART" (though this is
not the recommended way).
Alternatively, the 4.x way to specify "vinum.drives" is also supported.
No further hacks (like the 4.x "vinum.root" variable) are needed,
since in 5.x, mountroot() asks back at the drivers to have them
resolve the name of the root FS into a dev_t (using the dev_clone
eventhandler).
(The MFC reminder below is for a partial MFC for vinum.autostart, the
rest is already there in 4.x.)
Timed out on: grog
MFC after: 2 weeks
2003-02-05 21:02:56 +00:00
|
|
|
|
if (dsw == NULL) /* sanity, should not happen */
|
2000-08-16 04:31:37 +00:00
|
|
|
|
drive->lasterror = ENOENT;
|
Finally make vinum ready for the root filesystem in FreeBSD 5.x. (A
similar patch has been in 4.x for a while, but is more hacky there.)
For this to work, vinum has to be loaded early (e. g. from
boot/loader), for obvious reasons. If the kernel env variable
(aka. loader variable) "vinum.autostart" is set, vinum then asks the
sysctl kern.disks for all available disks in the system, and scans
them for possible vinum headers.
For statically compiled kernels, this behaviour can be obtained even
without boot/loader by using "options VINUM_AUTOSTART" (though this is
not the recommended way).
Alternatively, the 4.x way to specify "vinum.drives" is also supported.
No further hacks (like the 4.x "vinum.root" variable) are needed,
since in 5.x, mountroot() asks back at the drivers to have them
resolve the name of the root FS into a dev_t (using the dev_clone
eventhandler).
(The MFC reminder below is for a partial MFC for vinum.autostart, the
rest is already there in 4.x.)
Timed out on: grog
MFC after: 2 weeks
2003-02-05 21:02:56 +00:00
|
|
|
|
else if ((dsw->d_flags & D_DISK) == 0)
|
|
|
|
|
drive->lasterror = ENOTBLK;
|
2003-08-15 03:57:15 +00:00
|
|
|
|
else {
|
|
|
|
|
DROP_GIANT();
|
2002-10-05 03:44:00 +00:00
|
|
|
|
drive->lasterror = (dsw->d_open) (drive->dev, FWRITE | FREAD, 0, NULL);
|
2003-08-15 03:57:15 +00:00
|
|
|
|
PICKUP_GIANT();
|
|
|
|
|
}
|
2000-02-29 06:11:13 +00:00
|
|
|
|
|
|
|
|
|
if (drive->lasterror != 0) { /* failed */
|
|
|
|
|
drive->state = drive_down; /* just force it down */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
if (verbose)
|
1999-03-02 06:54:30 +00:00
|
|
|
|
log(LOG_WARNING,
|
2000-02-29 06:11:13 +00:00
|
|
|
|
"vinum open_drive %s: failed with error %d\n",
|
|
|
|
|
drive->devicename, drive->lasterror);
|
|
|
|
|
} else
|
|
|
|
|
drive->flags |= VF_OPEN; /* we're open now */
|
|
|
|
|
|
|
|
|
|
return drive->lasterror;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* Set some variables in the drive struct in more
|
|
|
|
|
* convenient form. Return error indication.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
|
set_drive_parms(struct drive *drive)
|
|
|
|
|
{
|
1999-08-14 06:26:32 +00:00
|
|
|
|
drive->blocksize = BLKDEV_IOSIZE; /* do we need this? */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
drive->secsperblock = drive->blocksize /* number of sectors per block */
|
2002-04-02 11:40:45 +00:00
|
|
|
|
/ drive->sectorsize;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
|
|
/* Now update the label part */
|
|
|
|
|
bcopy(hostname, drive->label.sysname, VINUMHOSTNAMELEN); /* put in host name */
|
2003-05-01 01:30:31 +00:00
|
|
|
|
microtime(&drive->label.date_of_birth); /* and current time */
|
|
|
|
|
drive->label.drive_size = drive->mediasize; /* size of the drive in bytes */
|
2001-05-23 23:24:05 +00:00
|
|
|
|
#ifdef VINUMDEBUG
|
1999-03-19 07:13:31 +00:00
|
|
|
|
if (debug & DEBUG_BIGDRIVE) /* pretend we're 100 times as big */
|
|
|
|
|
drive->label.drive_size *= 100;
|
|
|
|
|
#endif
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
|
|
/* number of sectors available for subdisks */
|
|
|
|
|
drive->sectors_available = drive->label.drive_size / DEV_BSIZE - DATASTART;
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* Bug in 3.0 as of January 1998: you can open
|
|
|
|
|
* non-existent slices. They have a length of 0.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
|
if (drive->label.drive_size < MINVINUMSLICE) { /* too small to worry about */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
set_drive_state(drive->driveno, drive_down, setstate_force);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
drive->lasterror = ENOSPC;
|
|
|
|
|
return ENOSPC;
|
|
|
|
|
}
|
|
|
|
|
drive->freelist_size = INITIAL_DRIVE_FREELIST; /* initial number of entries */
|
|
|
|
|
drive->freelist = (struct drive_freelist *)
|
|
|
|
|
Malloc(INITIAL_DRIVE_FREELIST * sizeof(struct drive_freelist));
|
|
|
|
|
if (drive->freelist == NULL) /* can't malloc, dammit */
|
|
|
|
|
return ENOSPC;
|
|
|
|
|
drive->freelist_entries = 1; /* just (almost) the complete drive */
|
|
|
|
|
drive->freelist[0].offset = DATASTART; /* starts here */
|
|
|
|
|
drive->freelist[0].sectors = (drive->label.drive_size >> DEV_BSHIFT) - DATASTART; /* and it's this long */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
if (drive->label.name[0] != '\0') /* got a name */
|
|
|
|
|
set_drive_state(drive->driveno, drive_up, setstate_force); /* our drive is accessible */
|
|
|
|
|
else /* we know about it, but that's all */
|
1999-03-02 06:54:30 +00:00
|
|
|
|
drive->state = drive_referenced;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* Initialize a drive: open the device and add
|
|
|
|
|
* device information.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
int
|
1999-01-21 00:35:35 +00:00
|
|
|
|
init_drive(struct drive *drive, int verbose)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
Finally make vinum ready for the root filesystem in FreeBSD 5.x. (A
similar patch has been in 4.x for a while, but is more hacky there.)
For this to work, vinum has to be loaded early (e. g. from
boot/loader), for obvious reasons. If the kernel env variable
(aka. loader variable) "vinum.autostart" is set, vinum then asks the
sysctl kern.disks for all available disks in the system, and scans
them for possible vinum headers.
For statically compiled kernels, this behaviour can be obtained even
without boot/loader by using "options VINUM_AUTOSTART" (though this is
not the recommended way).
Alternatively, the 4.x way to specify "vinum.drives" is also supported.
No further hacks (like the 4.x "vinum.root" variable) are needed,
since in 5.x, mountroot() asks back at the drivers to have them
resolve the name of the root FS into a dev_t (using the dev_clone
eventhandler).
(The MFC reminder below is for a partial MFC for vinum.autostart, the
rest is already there in 4.x.)
Timed out on: grog
MFC after: 2 weeks
2003-02-05 21:02:56 +00:00
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
|
drive->lasterror = open_drive(drive, curthread, verbose); /* open the drive */
|
2000-08-16 04:31:37 +00:00
|
|
|
|
if (drive->lasterror)
|
|
|
|
|
return drive->lasterror;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
2003-08-15 03:57:15 +00:00
|
|
|
|
DROP_GIANT();
|
2000-08-16 04:31:37 +00:00
|
|
|
|
drive->lasterror = (*devsw(drive->dev)->d_ioctl) (drive->dev,
|
2002-04-02 11:40:45 +00:00
|
|
|
|
DIOCGSECTORSIZE,
|
|
|
|
|
(caddr_t) & drive->sectorsize,
|
1998-12-28 04:56:24 +00:00
|
|
|
|
FREAD,
|
2001-09-12 08:38:13 +00:00
|
|
|
|
curthread);
|
2002-04-02 11:40:45 +00:00
|
|
|
|
if (drive->lasterror == 0)
|
2003-05-01 01:30:31 +00:00
|
|
|
|
drive->lasterror = (*devsw(drive->dev)->d_ioctl) (drive->dev,
|
|
|
|
|
DIOCGMEDIASIZE,
|
|
|
|
|
(caddr_t) & drive->mediasize,
|
|
|
|
|
FREAD,
|
|
|
|
|
curthread);
|
2003-08-15 03:57:15 +00:00
|
|
|
|
PICKUP_GIANT();
|
2000-08-16 04:31:37 +00:00
|
|
|
|
if (drive->lasterror) {
|
1999-01-21 00:35:35 +00:00
|
|
|
|
if (verbose)
|
2003-05-01 01:30:31 +00:00
|
|
|
|
log(LOG_ERR,
|
2003-05-19 02:21:31 +00:00
|
|
|
|
"vinum: Can't get drive dimensions for %s: error %d\n",
|
1999-01-21 00:35:35 +00:00
|
|
|
|
drive->devicename,
|
2000-08-16 04:31:37 +00:00
|
|
|
|
drive->lasterror);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
close_drive(drive);
|
2000-08-16 04:31:37 +00:00
|
|
|
|
return drive->lasterror;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
return set_drive_parms(drive); /* set various odds and ends */
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-24 08:55:02 +00:00
|
|
|
|
/* Close a drive if it's open. */
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
|
close_drive(struct drive *drive)
|
|
|
|
|
{
|
1999-06-29 04:08:51 +00:00
|
|
|
|
LOCKDRIVE(drive); /* keep the daemon out */
|
2000-02-29 06:11:13 +00:00
|
|
|
|
if (drive->flags & VF_OPEN)
|
1999-06-24 08:55:02 +00:00
|
|
|
|
close_locked_drive(drive); /* and close it */
|
1999-09-28 22:46:39 +00:00
|
|
|
|
if (drive->state > drive_down) /* if it's up */
|
|
|
|
|
drive->state = drive_down; /* make sure it's down */
|
1999-06-29 04:08:51 +00:00
|
|
|
|
unlockdrive(drive);
|
1999-06-24 08:55:02 +00:00
|
|
|
|
}
|
1999-05-02 07:51:20 +00:00
|
|
|
|
|
1999-06-24 08:55:02 +00:00
|
|
|
|
/*
|
1999-08-07 08:07:05 +00:00
|
|
|
|
* Real drive close code, called with drive already locked.
|
|
|
|
|
* We have also checked that the drive is open. No errors.
|
1999-06-24 08:55:02 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1999-06-24 08:55:02 +00:00
|
|
|
|
close_locked_drive(struct drive *drive)
|
|
|
|
|
{
|
2002-10-05 03:44:00 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
1999-06-24 08:55:02 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* If we can't access the drive, we can't flush
|
1999-06-24 08:55:02 +00:00
|
|
|
|
* the queues, which spec_close() will try to
|
|
|
|
|
* do. Get rid of them here first.
|
|
|
|
|
*/
|
2003-08-15 03:57:15 +00:00
|
|
|
|
DROP_GIANT();
|
2003-01-22 14:06:46 +00:00
|
|
|
|
error = (*devsw(drive->dev)->d_close) (drive->dev, FWRITE | FREAD, 0, NULL);
|
2003-08-15 03:57:15 +00:00
|
|
|
|
PICKUP_GIANT();
|
2000-02-29 06:11:13 +00:00
|
|
|
|
drive->flags &= ~VF_OPEN; /* no longer open */
|
2002-10-05 03:44:00 +00:00
|
|
|
|
if (drive->lasterror == 0)
|
|
|
|
|
drive->lasterror = error;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Remove drive from the configuration.
|
2000-05-04 07:35:03 +00:00
|
|
|
|
* Caller must ensure that it isn't active.
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
|
remove_drive(int driveno)
|
|
|
|
|
{
|
|
|
|
|
struct drive *drive = &vinum_conf.drive[driveno];
|
2000-05-04 07:35:03 +00:00
|
|
|
|
struct vinum_hdr *vhdr; /* buffer for header */
|
|
|
|
|
int error;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
1999-03-30 05:00:19 +00:00
|
|
|
|
if (drive->state > drive_referenced) { /* real drive */
|
2000-05-04 07:35:03 +00:00
|
|
|
|
if (drive->state == drive_up) {
|
|
|
|
|
vhdr = (struct vinum_hdr *) Malloc(VINUMHEADERLEN); /* allocate buffer */
|
|
|
|
|
CHECKALLOC(vhdr, "Can't allocate memory");
|
|
|
|
|
error = read_drive(drive, (void *) vhdr, VINUMHEADERLEN, VINUM_LABEL_OFFSET);
|
|
|
|
|
if (error)
|
|
|
|
|
drive->lasterror = error;
|
|
|
|
|
else {
|
|
|
|
|
vhdr->magic = VINUM_NOMAGIC; /* obliterate the magic, but leave the rest */
|
|
|
|
|
write_drive(drive, (void *) vhdr, VINUMHEADERLEN, VINUM_LABEL_OFFSET);
|
|
|
|
|
}
|
|
|
|
|
Free(vhdr);
|
|
|
|
|
}
|
1999-03-30 05:00:19 +00:00
|
|
|
|
free_drive(drive); /* close it and free resources */
|
|
|
|
|
save_config(); /* and save the updated configuration */
|
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2000-02-29 06:11:13 +00:00
|
|
|
|
* Transfer drive data. Usually called from one of these defines;
|
|
|
|
|
* #define read_drive(a, b, c, d) driveio (a, b, c, d, B_READ)
|
|
|
|
|
* #define write_drive(a, b, c, d) driveio (a, b, c, d, B_WRITE)
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*
|
2000-02-29 06:11:13 +00:00
|
|
|
|
* length and offset are in bytes, but must be multiples of sector
|
|
|
|
|
* size. The function *does not check* for this condition, and
|
|
|
|
|
* truncates ruthlessly.
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* Return error number.
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
int
|
2000-02-29 06:11:13 +00:00
|
|
|
|
driveio(struct drive *drive, char *buf, size_t length, off_t offset, int flag)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
|
|
|
|
int error;
|
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
2000-02-29 06:11:13 +00:00
|
|
|
|
error = 0; /* to keep the compiler happy */
|
|
|
|
|
while (length) { /* divide into small enough blocks */
|
|
|
|
|
int len = min(length, MAXBSIZE); /* maximum block device transfer is MAXBSIZE */
|
|
|
|
|
|
|
|
|
|
bp = geteblk(len); /* get a buffer header */
|
2000-03-20 10:44:49 +00:00
|
|
|
|
bp->b_flags = 0;
|
|
|
|
|
bp->b_iocmd = flag;
|
2000-02-29 06:11:13 +00:00
|
|
|
|
bp->b_dev = drive->dev; /* device */
|
2003-05-01 01:30:31 +00:00
|
|
|
|
bp->b_blkno = offset / drive->sectorsize; /* block number */
|
2003-11-23 17:10:58 +00:00
|
|
|
|
bp->b_offset = offset;
|
2000-02-29 06:11:13 +00:00
|
|
|
|
bp->b_saveaddr = bp->b_data;
|
|
|
|
|
bp->b_data = buf;
|
|
|
|
|
bp->b_bcount = len;
|
2003-01-03 05:57:35 +00:00
|
|
|
|
DEV_STRATEGY(bp); /* initiate the transfer */
|
2000-04-29 16:25:22 +00:00
|
|
|
|
error = bufwait(bp);
|
2000-02-29 06:11:13 +00:00
|
|
|
|
bp->b_data = bp->b_saveaddr;
|
|
|
|
|
bp->b_flags |= B_INVAL | B_AGE;
|
2000-04-02 15:24:56 +00:00
|
|
|
|
bp->b_ioflags &= ~BIO_ERROR;
|
2000-02-29 06:11:13 +00:00
|
|
|
|
brelse(bp);
|
|
|
|
|
if (error)
|
|
|
|
|
break;
|
|
|
|
|
length -= len; /* update pointers */
|
|
|
|
|
buf += len;
|
|
|
|
|
offset += len;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
2000-02-29 06:11:13 +00:00
|
|
|
|
return error;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* Check a drive for a vinum header. If found,
|
1998-12-28 04:56:24 +00:00
|
|
|
|
* update the drive information. We come here
|
|
|
|
|
* with a partially populated drive structure
|
|
|
|
|
* which includes the device name.
|
|
|
|
|
*
|
1999-01-21 00:35:35 +00:00
|
|
|
|
* Return information on what we found.
|
|
|
|
|
*
|
|
|
|
|
* This function is called from two places: check_drive,
|
|
|
|
|
* which wants to find out whether the drive is a
|
|
|
|
|
* Vinum drive, and config_drive, which asserts that
|
|
|
|
|
* it is a vinum drive. In the first case, we don't
|
|
|
|
|
* print error messages (verbose==0), in the second
|
|
|
|
|
* we do (verbose==1).
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
enum drive_label_info
|
1999-01-21 00:35:35 +00:00
|
|
|
|
read_drive_label(struct drive *drive, int verbose)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
|
|
|
|
int error;
|
|
|
|
|
int result; /* result of our search */
|
|
|
|
|
struct vinum_hdr *vhdr; /* and as header */
|
|
|
|
|
|
1999-01-21 00:35:35 +00:00
|
|
|
|
error = init_drive(drive, 0); /* find the drive */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
if (error) /* find the drive */
|
|
|
|
|
return DL_CANT_OPEN; /* not ours */
|
|
|
|
|
|
|
|
|
|
vhdr = (struct vinum_hdr *) Malloc(VINUMHEADERLEN); /* allocate buffers */
|
|
|
|
|
CHECKALLOC(vhdr, "Can't allocate memory");
|
|
|
|
|
|
2000-08-16 04:31:37 +00:00
|
|
|
|
drive->state = drive_up; /* be optimistic */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
error = read_drive(drive, (void *) vhdr, VINUMHEADERLEN, VINUM_LABEL_OFFSET);
|
|
|
|
|
if (vhdr->magic == VINUM_MAGIC) { /* ours! */
|
|
|
|
|
if (drive->label.name[0] /* we have a name for this drive */
|
|
|
|
|
&&(strcmp(drive->label.name, vhdr->label.name))) { /* but it doesn't match the real name */
|
|
|
|
|
drive->lasterror = EINVAL;
|
|
|
|
|
result = DL_WRONG_DRIVE; /* it's the wrong drive */
|
2000-08-16 04:31:37 +00:00
|
|
|
|
drive->state = drive_unallocated; /* put it back, it's not ours */
|
|
|
|
|
} else
|
1998-12-28 04:56:24 +00:00
|
|
|
|
result = DL_OURS;
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* We copy the drive anyway so that we have
|
1998-12-28 04:56:24 +00:00
|
|
|
|
* the correct name in the drive info. This
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* may not be the name specified
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
|
drive->label = vhdr->label; /* put in the label information */
|
|
|
|
|
} else if (vhdr->magic == VINUM_NOMAGIC) /* was ours, but we gave it away */
|
1999-03-23 04:48:05 +00:00
|
|
|
|
result = DL_DELETED_LABEL; /* and return the info */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
else
|
|
|
|
|
result = DL_NOT_OURS; /* we could have it, but we don't yet */
|
|
|
|
|
Free(vhdr); /* that's all. */
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* Check a drive for a vinum header. If found,
|
1998-12-28 04:56:24 +00:00
|
|
|
|
* read configuration information from the drive and
|
|
|
|
|
* incorporate the data into the configuration.
|
|
|
|
|
*
|
1999-02-11 06:43:15 +00:00
|
|
|
|
* Return drive number.
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
1999-01-21 00:35:35 +00:00
|
|
|
|
struct drive *
|
1999-05-02 07:51:20 +00:00
|
|
|
|
check_drive(char *devicename)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
|
|
|
|
int driveno;
|
1999-02-11 06:43:15 +00:00
|
|
|
|
int i;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
struct drive *drive;
|
|
|
|
|
|
2003-05-01 01:30:31 +00:00
|
|
|
|
driveno = find_drive_by_name(devicename, 1); /* if entry doesn't exist, create it */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
drive = &vinum_conf.drive[driveno]; /* and get a pointer */
|
|
|
|
|
|
2003-05-02 06:04:19 +00:00
|
|
|
|
if (drive->state >= drive_down) /* up or down, we know it */
|
|
|
|
|
return drive;
|
1999-08-16 05:08:46 +00:00
|
|
|
|
if (read_drive_label(drive, 0) == DL_OURS) { /* one of ours */
|
1999-05-02 07:51:20 +00:00
|
|
|
|
for (i = 0; i < vinum_conf.drives_allocated; i++) { /* see if the name already exists */
|
|
|
|
|
if ((i != driveno) /* not this drive */
|
2001-01-14 06:33:10 +00:00
|
|
|
|
&&(DRIVE[i].state != drive_unallocated) /* and it's allocated */
|
2001-01-10 05:02:44 +00:00
|
|
|
|
&&(strcmp(DRIVE[i].label.name,
|
1999-05-02 07:51:20 +00:00
|
|
|
|
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 */
|
|
|
|
|
/*
|
1999-08-16 05:08:46 +00:00
|
|
|
|
* set an error, but don't take the
|
|
|
|
|
* drive down: that would cause unneeded
|
|
|
|
|
* error messages.
|
1999-05-02 07:51:20 +00:00
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
}
|
1999-03-02 06:54:30 +00:00
|
|
|
|
}
|
1999-05-02 07:51:20 +00:00
|
|
|
|
bzero(mydrive, sizeof(struct drive)); /* don't deallocate it, just remove it */
|
1999-03-02 06:54:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-02-11 06:43:15 +00:00
|
|
|
|
}
|
2003-06-15 01:42:01 +00:00
|
|
|
|
return drive;
|
|
|
|
|
} else { /* not ours, */
|
1999-10-13 03:17:59 +00:00
|
|
|
|
close_drive(drive);
|
2003-06-15 01:42:01 +00:00
|
|
|
|
free_drive(drive); /* get rid of it */
|
|
|
|
|
return NULL;
|
1999-02-11 06:43:15 +00:00
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
sappend(char *txt, char *s)
|
|
|
|
|
{
|
1999-01-27 20:09:21 +00:00
|
|
|
|
while ((*s++ = *txt++) != 0);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
return s - 1;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1999-01-28 06:59:27 +00:00
|
|
|
|
format_config(char *config, int len)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
1999-01-28 06:59:27 +00:00
|
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
|
char *s = config;
|
1999-08-07 08:07:05 +00:00
|
|
|
|
char *configend = &config[len];
|
1999-01-28 06:59:27 +00:00
|
|
|
|
|
|
|
|
|
bzero(config, len);
|
|
|
|
|
|
1999-08-07 08:07:05 +00:00
|
|
|
|
/* First write the volume configuration */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
for (i = 0; i < vinum_conf.volumes_allocated; i++) {
|
1999-01-28 06:59:27 +00:00
|
|
|
|
struct volume *vol;
|
|
|
|
|
|
|
|
|
|
vol = &vinum_conf.volume[i];
|
1999-03-30 05:00:19 +00:00
|
|
|
|
if ((vol->state > volume_uninit)
|
1999-03-02 06:54:30 +00:00
|
|
|
|
&& (vol->name[0] != '\0')) { /* paranoia */
|
1999-08-16 05:08:46 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
|
|
|
|
"volume %s state %s",
|
|
|
|
|
vol->name,
|
|
|
|
|
volume_state(vol->state));
|
2000-06-02 04:03:13 +00:00
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
1999-01-28 06:59:27 +00:00
|
|
|
|
s = sappend("\n", s);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-28 06:59:27 +00:00
|
|
|
|
/* Then the plex configuration */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
for (i = 0; i < vinum_conf.plexes_allocated; i++) {
|
1999-01-28 06:59:27 +00:00
|
|
|
|
struct plex *plex;
|
2003-05-05 05:32:52 +00:00
|
|
|
|
struct volume *vol;
|
1999-01-28 06:59:27 +00:00
|
|
|
|
|
|
|
|
|
plex = &vinum_conf.plex[i];
|
2000-02-29 06:11:13 +00:00
|
|
|
|
if ((plex->state > plex_referenced)
|
1999-03-02 06:54:30 +00:00
|
|
|
|
&& (plex->name[0] != '\0')) { /* paranoia */
|
1999-08-07 08:07:05 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
|
|
|
|
"plex name %s state %s org %s ",
|
1999-01-28 06:59:27 +00:00
|
|
|
|
plex->name,
|
|
|
|
|
plex_state(plex->state),
|
|
|
|
|
plex_org(plex->organization));
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
2000-02-29 06:11:13 +00:00
|
|
|
|
if (isstriped(plex)) {
|
1999-08-07 08:07:05 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
|
|
|
|
"%ds ",
|
|
|
|
|
(int) plex->stripesize);
|
1999-01-28 06:59:27 +00:00
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
|
|
|
|
}
|
2003-05-05 05:32:52 +00:00
|
|
|
|
if (plex->volno >= 0) { /* we have a volume */
|
|
|
|
|
vol = &VOL[plex->volno];
|
1999-08-07 08:07:05 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
|
|
|
|
"vol %s ",
|
2003-05-05 05:32:52 +00:00
|
|
|
|
vol->name);
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
|
|
|
|
if ((vol->preferred_plex >= 0) /* has a preferred plex */
|
|
|
|
|
&&vol->plex[vol->preferred_plex] == i) /* and it's us */
|
|
|
|
|
snprintf(s, configend - s, "preferred ");
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
|
|
|
|
}
|
1999-01-28 06:59:27 +00:00
|
|
|
|
for (j = 0; j < plex->subdisks; j++) {
|
1999-08-07 08:07:05 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
|
|
|
|
" sd %s",
|
|
|
|
|
vinum_conf.sd[plex->sdnos[j]].name);
|
1999-01-28 06:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
s = sappend("\n", s);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
1999-01-28 06:59:27 +00:00
|
|
|
|
|
|
|
|
|
/* And finally the subdisk configuration */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
for (i = 0; i < vinum_conf.subdisks_allocated; i++) {
|
|
|
|
|
struct sd *sd;
|
2001-01-14 06:33:10 +00:00
|
|
|
|
char *drivename;
|
1999-03-30 05:00:19 +00:00
|
|
|
|
|
|
|
|
|
sd = &SD[i];
|
|
|
|
|
if ((sd->state != sd_referenced)
|
2000-02-29 06:11:13 +00:00
|
|
|
|
&& (sd->state != sd_unallocated)
|
1999-03-02 06:54:30 +00:00
|
|
|
|
&& (sd->name[0] != '\0')) { /* paranoia */
|
2001-01-14 06:33:10 +00:00
|
|
|
|
drivename = vinum_conf.drive[sd->driveno].label.name;
|
|
|
|
|
/*
|
|
|
|
|
* XXX We've seen cases of dead subdisks
|
|
|
|
|
* which don't have a drive. If we let them
|
|
|
|
|
* through here, the drive name is null, so
|
|
|
|
|
* they get the drive named 'plex'.
|
|
|
|
|
*
|
|
|
|
|
* This is a breakage limiter, not a fix.
|
|
|
|
|
*/
|
|
|
|
|
if (drivename[0] == '\0')
|
|
|
|
|
drivename = "*invalid*";
|
2001-05-22 02:32:22 +00:00
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
2003-05-19 02:21:31 +00:00
|
|
|
|
"sd name %s drive %s len %llus driveoffset %llus state %s",
|
2001-05-22 02:32:22 +00:00
|
|
|
|
sd->name,
|
|
|
|
|
drivename,
|
|
|
|
|
(unsigned long long) sd->sectors,
|
|
|
|
|
(unsigned long long) sd->driveoffset,
|
|
|
|
|
sd_state(sd->state));
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
1999-08-07 08:07:05 +00:00
|
|
|
|
if (sd->plexno >= 0)
|
|
|
|
|
snprintf(s,
|
|
|
|
|
configend - s,
|
2003-05-19 02:21:31 +00:00
|
|
|
|
" plex %s plexoffset %llds",
|
|
|
|
|
vinum_conf.plex[sd->plexno].name,
|
1999-08-08 14:11:03 +00:00
|
|
|
|
(long long) sd->plexoffset);
|
1999-08-07 08:07:05 +00:00
|
|
|
|
else
|
2001-05-22 02:32:22 +00:00
|
|
|
|
snprintf(s, configend - s, " detached");
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
|
|
|
|
if (sd->flags & VF_RETRYERRORS) {
|
|
|
|
|
snprintf(s, configend - s, " retryerrors");
|
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
|
|
|
|
}
|
|
|
|
|
snprintf(s, configend - s, " \n");
|
1999-01-28 06:59:27 +00:00
|
|
|
|
while (*s)
|
|
|
|
|
s++; /* find the end */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-08-07 08:07:05 +00:00
|
|
|
|
if (s > &config[len - 2])
|
|
|
|
|
panic("vinum: configuration data overflow");
|
1999-01-28 06:59:27 +00:00
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* issue a save config request to the d<EFBFBD>mon. The actual work
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* is done in process context by daemon_save_config.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
|
save_config(void)
|
|
|
|
|
{
|
2002-08-21 23:39:52 +00:00
|
|
|
|
queue_daemon_request(daemonrq_saveconfig, (union daemoninfo) 0);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Write the configuration to all vinum slices. This
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* is performed by the daemon only.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1999-01-21 00:35:35 +00:00
|
|
|
|
daemon_save_config(void)
|
|
|
|
|
{
|
1998-12-28 04:56:24 +00:00
|
|
|
|
int error;
|
1999-01-21 00:35:35 +00:00
|
|
|
|
int written_config; /* set when we first write the config to disk */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
int driveno;
|
|
|
|
|
struct drive *drive; /* point to current drive info */
|
|
|
|
|
struct vinum_hdr *vhdr; /* and as header */
|
|
|
|
|
char *config; /* point to config data */
|
|
|
|
|
|
|
|
|
|
/* don't save the configuration while we're still working on it */
|
|
|
|
|
if (vinum_conf.flags & VF_CONFIGURING)
|
1999-01-21 00:35:35 +00:00
|
|
|
|
return;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
written_config = 0; /* no config written yet */
|
|
|
|
|
/* Build a volume header */
|
|
|
|
|
vhdr = (struct vinum_hdr *) Malloc(VINUMHEADERLEN); /* get space for the config data */
|
|
|
|
|
CHECKALLOC(vhdr, "Can't allocate config data");
|
|
|
|
|
vhdr->magic = VINUM_MAGIC; /* magic number */
|
|
|
|
|
vhdr->config_length = MAXCONFIG; /* length of following config info */
|
|
|
|
|
|
|
|
|
|
config = Malloc(MAXCONFIG); /* get space for the config data */
|
|
|
|
|
CHECKALLOC(config, "Can't allocate config data");
|
|
|
|
|
|
|
|
|
|
format_config(config, MAXCONFIG);
|
|
|
|
|
error = 0; /* no errors yet */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
for (driveno = 0; driveno < vinum_conf.drives_allocated; driveno++) {
|
1998-12-28 04:56:24 +00:00
|
|
|
|
drive = &vinum_conf.drive[driveno]; /* point to drive */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
if (drive->state > drive_referenced) {
|
1999-04-10 08:10:24 +00:00
|
|
|
|
LOCKDRIVE(drive); /* don't let it change */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
1999-03-30 05:00:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* First, do some drive consistency checks. Some
|
|
|
|
|
* of these are kludges, others require a process
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* context and couldn't be done before.
|
1999-03-30 05:00:19 +00:00
|
|
|
|
*/
|
1999-08-14 06:26:32 +00:00
|
|
|
|
if ((drive->devicename[0] == '\0')
|
|
|
|
|
|| (drive->label.name[0] == '\0')) {
|
1999-03-30 05:00:19 +00:00
|
|
|
|
unlockdrive(drive);
|
|
|
|
|
free_drive(drive); /* get rid of it */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-02-29 06:11:13 +00:00
|
|
|
|
if (((drive->flags & VF_OPEN) == 0) /* drive not open */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
&&(drive->state > drive_down)) { /* and it thinks it's not down */
|
|
|
|
|
unlockdrive(drive);
|
|
|
|
|
set_drive_state(driveno, drive_down, setstate_force); /* tell it what's what */
|
1999-04-10 08:10:24 +00:00
|
|
|
|
continue;
|
1999-03-30 05:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
if ((drive->state == drive_down) /* it's down */
|
2000-02-29 06:11:13 +00:00
|
|
|
|
&&(drive->flags & VF_OPEN)) { /* but open, */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
unlockdrive(drive);
|
|
|
|
|
close_drive(drive); /* close it */
|
|
|
|
|
} else if (drive->state > drive_down) {
|
2003-05-01 01:30:31 +00:00
|
|
|
|
microtime(&drive->label.last_update); /* time of last update is now */
|
1999-03-30 05:00:19 +00:00
|
|
|
|
bcopy((char *) &drive->label, /* and the label info from the drive structure */
|
|
|
|
|
(char *) &vhdr->label,
|
|
|
|
|
sizeof(vhdr->label));
|
|
|
|
|
if ((drive->state != drive_unallocated)
|
|
|
|
|
&& (drive->state != drive_referenced)) { /* and it's a real drive */
|
2003-05-01 01:30:31 +00:00
|
|
|
|
error = write_drive(drive,
|
|
|
|
|
(char *) vhdr,
|
|
|
|
|
VINUMHEADERLEN,
|
|
|
|
|
VINUM_LABEL_OFFSET);
|
|
|
|
|
if (error == 0) /* first config copy */
|
|
|
|
|
error = write_drive(drive,
|
|
|
|
|
config,
|
|
|
|
|
MAXCONFIG,
|
|
|
|
|
VINUM_CONFIG_OFFSET);
|
1999-03-30 05:00:19 +00:00
|
|
|
|
if (error == 0)
|
2003-05-01 01:30:31 +00:00
|
|
|
|
error = write_drive(drive, /* second copy */
|
|
|
|
|
config,
|
|
|
|
|
MAXCONFIG,
|
|
|
|
|
VINUM_CONFIG_OFFSET + MAXCONFIG);
|
1999-03-30 05:00:19 +00:00
|
|
|
|
unlockdrive(drive);
|
|
|
|
|
if (error) {
|
|
|
|
|
log(LOG_ERR,
|
|
|
|
|
"vinum: Can't write config to %s, error %d\n",
|
|
|
|
|
drive->devicename,
|
|
|
|
|
error);
|
|
|
|
|
set_drive_state(drive->driveno, drive_down, setstate_force);
|
|
|
|
|
} else
|
|
|
|
|
written_config = 1; /* we've written it on at least one drive */
|
|
|
|
|
}
|
1999-04-10 08:10:24 +00:00
|
|
|
|
} else /* not worth looking at, */
|
|
|
|
|
unlockdrive(drive); /* just unlock it again */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Free(vhdr);
|
|
|
|
|
Free(config);
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* Disk labels are a mess. The correct way to
|
|
|
|
|
* access them is with the DIOC[GSW]DINFO ioctls,
|
|
|
|
|
* but some programs, such as newfs, access the
|
|
|
|
|
* disk directly, so we have to write things
|
|
|
|
|
* there. We do this only on request. If a user
|
|
|
|
|
* request tries to read it directly, we fake up
|
|
|
|
|
* one on the fly.
|
1998-12-28 04:56:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* get_volume_label returns a label structure to
|
|
|
|
|
* lp, which is allocated by the caller.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
void
|
1999-08-14 06:26:32 +00:00
|
|
|
|
get_volume_label(char *name, int plexes, u_int64_t size, struct disklabel *lp)
|
1998-12-28 04:56:24 +00:00
|
|
|
|
{
|
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, "vinum", sizeof(lp->d_typename));
|
|
|
|
|
lp->d_type = DTYPE_VINUM;
|
1999-08-14 06:26:32 +00:00
|
|
|
|
strncpy(lp->d_packname, name, min(sizeof(lp->d_packname), sizeof(name)));
|
|
|
|
|
lp->d_rpm = 14400 * plexes; /* to keep them guessing */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2000-06-02 04:03:13 +00:00
|
|
|
|
* A Vinum volume has a single track with all
|
|
|
|
|
* its sectors.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_secsize = DEV_BSIZE; /* bytes per sector */
|
1999-08-14 06:26:32 +00:00
|
|
|
|
lp->d_nsectors = size; /* data sectors per track */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_ntracks = 1; /* tracks per cylinder */
|
|
|
|
|
lp->d_ncylinders = 1; /* data cylinders per unit */
|
1999-08-14 06:26:32 +00:00
|
|
|
|
lp->d_secpercyl = size; /* data sectors per cylinder */
|
|
|
|
|
lp->d_secperunit = size; /* data sectors per unit */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
|
|
lp->d_bbsize = BBSIZE;
|
2003-05-01 01:30:31 +00:00
|
|
|
|
lp->d_sbsize = 0; /* no longer used? */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Set up partitions a, b and c to be identical
|
1998-12-28 04:56:24 +00:00
|
|
|
|
* and the size of the volume. a is UFS, b is
|
2000-02-29 06:11:13 +00:00
|
|
|
|
* swap, c is nothing.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-14 06:26:32 +00:00
|
|
|
|
lp->d_partitions[0].p_size = size;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_partitions[0].p_fsize = 1024;
|
|
|
|
|
lp->d_partitions[0].p_fstype = FS_BSDFFS; /* FreeBSD File System :-) */
|
|
|
|
|
lp->d_partitions[0].p_fsize = 1024; /* FS fragment size */
|
|
|
|
|
lp->d_partitions[0].p_frag = 8; /* and fragments per block */
|
1999-08-14 06:26:32 +00:00
|
|
|
|
lp->d_partitions[SWAP_PART].p_size = size;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_partitions[SWAP_PART].p_fstype = FS_SWAP; /* swap partition */
|
1999-08-14 06:26:32 +00:00
|
|
|
|
lp->d_partitions[LABEL_PART].p_size = size;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_npartitions = LABEL_PART + 1;
|
1999-08-14 06:26:32 +00:00
|
|
|
|
strncpy(lp->d_packname, name, min(sizeof(lp->d_packname), sizeof(name)));
|
1998-12-28 04:56:24 +00:00
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-04 05:15:07 +00:00
|
|
|
|
/*
|
2003-08-15 03:57:15 +00:00
|
|
|
|
* Search disks on system for vinum slices and add
|
2003-05-04 05:15:07 +00:00
|
|
|
|
* them to the configuuration if they're not
|
|
|
|
|
* there already. devicename is a blank-separate
|
|
|
|
|
* list of device names. If not provided, use
|
|
|
|
|
* sysctl to get a list of all disks on the
|
|
|
|
|
* system.
|
|
|
|
|
*
|
|
|
|
|
* Return an error indication.
|
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
int
|
2003-05-04 05:15:07 +00:00
|
|
|
|
vinum_scandisk(char *devicename)
|
1999-01-21 00:35:35 +00:00
|
|
|
|
{
|
|
|
|
|
struct drive *volatile drive;
|
|
|
|
|
volatile int driveno;
|
|
|
|
|
int firstdrive; /* first drive in this list */
|
|
|
|
|
volatile int gooddrives; /* number of usable drives found */
|
|
|
|
|
int firsttime; /* set if we have never configured before */
|
|
|
|
|
int error;
|
|
|
|
|
char *config_text; /* read the config info from disk into here */
|
|
|
|
|
char *volatile cptr; /* pointer into config information */
|
|
|
|
|
char *eptr; /* end pointer into config information */
|
|
|
|
|
char *config_line; /* copy the config line to */
|
|
|
|
|
volatile int status;
|
2003-05-04 05:15:07 +00:00
|
|
|
|
int *drivelist; /* list of drive indices */
|
|
|
|
|
char *partname; /* for creating partition names */
|
|
|
|
|
char *cp; /* pointer to start of disk name */
|
|
|
|
|
char *ep; /* and to first char after name */
|
|
|
|
|
char *np; /* name pointer in naem we build */
|
|
|
|
|
size_t alloclen;
|
|
|
|
|
int malloced;
|
|
|
|
|
int partnamelen; /* length of partition name */
|
|
|
|
|
int drives;
|
2003-08-15 04:36:53 +00:00
|
|
|
|
int goodpart; /* good vinum drives on this disk */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
|
|
|
|
|
malloced = 0; /* devicename not malloced */
|
|
|
|
|
if (devicename == NULL) { /* no devices specified, */
|
|
|
|
|
/* get a list of all disks in the system */
|
|
|
|
|
/* Get size of disk list */
|
|
|
|
|
error = kernel_sysctlbyname(&thread0, "kern.disks", NULL,
|
|
|
|
|
NULL, NULL, 0, &alloclen);
|
|
|
|
|
if (error) {
|
|
|
|
|
log(LOG_ERR, "vinum: can't get disk list: %d\n", error);
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
devicename = Malloc(alloclen);
|
|
|
|
|
if (devicename == NULL) {
|
|
|
|
|
printf("vinum: can't allocate memory for drive list");
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
} else
|
|
|
|
|
malloced = 1;
|
2003-05-05 05:32:52 +00:00
|
|
|
|
/* Now get the list of disks */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
kernel_sysctlbyname(&thread0, "kern.disks", devicename,
|
|
|
|
|
&alloclen, NULL, 0, NULL);
|
|
|
|
|
}
|
1999-01-21 00:35:35 +00:00
|
|
|
|
status = 0; /* success indication */
|
1999-03-19 07:13:31 +00:00
|
|
|
|
vinum_conf.flags |= VF_READING_CONFIG; /* reading config from disk */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
partname = Malloc(MAXPATHLEN); /* extract name of disk here */
|
|
|
|
|
if (partname == NULL) {
|
|
|
|
|
printf("vinum_scandisk: can't allocate memory for drive name");
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
}
|
1999-01-21 00:35:35 +00:00
|
|
|
|
gooddrives = 0; /* number of usable drives found */
|
|
|
|
|
firstdrive = vinum_conf.drives_used; /* the first drive */
|
|
|
|
|
firsttime = vinum_conf.drives_used == 0; /* are we a virgin? */
|
|
|
|
|
|
|
|
|
|
/* allocate a drive pointer list */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
drives = 256; /* should be enough for most cases */
|
|
|
|
|
drivelist = (int *) Malloc(drives * sizeof(int));
|
1999-01-21 00:35:35 +00:00
|
|
|
|
CHECKALLOC(drivelist, "Can't allocate memory");
|
2003-05-05 05:32:52 +00:00
|
|
|
|
error = lock_config(); /* make sure we're alone here */
|
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
|
|
|
|
error = setjmp(command_fail); /* come back here on error */
|
|
|
|
|
if (error) /* longjmped out */
|
|
|
|
|
return error;
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
|
|
|
|
/* Open all drives and find which was modified most recently */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
for (cp = devicename; *cp; cp = ep) {
|
1999-01-21 00:35:35 +00:00
|
|
|
|
char part; /* UNIX partition */
|
2003-08-15 17:56:44 +00:00
|
|
|
|
#ifdef __i386__
|
1999-08-07 08:07:05 +00:00
|
|
|
|
int slice;
|
2003-08-15 17:56:44 +00:00
|
|
|
|
#endif
|
1999-08-07 08:07:05 +00:00
|
|
|
|
|
2003-05-04 05:15:07 +00:00
|
|
|
|
while (*cp == ' ')
|
|
|
|
|
cp++; /* find start of name */
|
|
|
|
|
if (*cp == '\0') /* done, */
|
|
|
|
|
break;
|
|
|
|
|
ep = cp;
|
|
|
|
|
while (*ep && (*ep != ' ')) /* find end of name */
|
|
|
|
|
ep++;
|
|
|
|
|
|
|
|
|
|
np = partname; /* start building up a name here */
|
|
|
|
|
if (*cp != '/') { /* name doesn't start with /, */
|
|
|
|
|
strcpy(np, "/dev/"); /* assume /dev */
|
|
|
|
|
np += strlen("/dev/");
|
|
|
|
|
}
|
|
|
|
|
memcpy(np, cp, ep - cp); /* put in name */
|
|
|
|
|
np += ep - cp; /* and point past */
|
|
|
|
|
|
2003-08-15 04:36:53 +00:00
|
|
|
|
goodpart = 0; /* no partitions on this disk yet */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
partnamelen = MAXPATHLEN + np - partname; /* remaining length in partition name */
|
2003-08-15 03:57:15 +00:00
|
|
|
|
#ifdef __i386__
|
1999-08-07 08:07:05 +00:00
|
|
|
|
/* first try the partition table */
|
|
|
|
|
for (slice = 1; slice < 5; slice++)
|
|
|
|
|
for (part = 'a'; part < 'i'; part++) {
|
|
|
|
|
if (part != 'c') { /* don't do the c partition */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
snprintf(np,
|
|
|
|
|
partnamelen,
|
|
|
|
|
"s%d%c",
|
1999-08-07 08:07:05 +00:00
|
|
|
|
slice,
|
|
|
|
|
part);
|
|
|
|
|
drive = check_drive(partname); /* try to open it */
|
2003-06-15 01:42:01 +00:00
|
|
|
|
if (drive) { /* got something, */
|
|
|
|
|
if (drive->flags & VF_CONFIGURED) /* already read this config, */
|
|
|
|
|
log(LOG_WARNING,
|
|
|
|
|
"vinum: already read config from %s\n", /* say so */
|
|
|
|
|
drive->label.name);
|
|
|
|
|
else {
|
|
|
|
|
if (gooddrives == drives) /* ran out of entries */
|
|
|
|
|
EXPAND(drivelist, int, drives, drives); /* double the size */
|
|
|
|
|
drivelist[gooddrives] = drive->driveno; /* keep the drive index */
|
|
|
|
|
drive->flags &= ~VF_NEWBORN; /* which is no longer newly born */
|
|
|
|
|
gooddrives++;
|
2003-08-15 04:36:53 +00:00
|
|
|
|
goodpart++;
|
2003-06-15 01:42:01 +00:00
|
|
|
|
}
|
1999-08-07 08:07:05 +00:00
|
|
|
|
}
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-08-15 03:57:15 +00:00
|
|
|
|
#endif
|
2003-06-15 01:42:01 +00:00
|
|
|
|
/*
|
2003-08-15 03:57:15 +00:00
|
|
|
|
* If the machine doesn't have a BIOS
|
|
|
|
|
* partition table, try normal devices.
|
2003-06-15 01:42:01 +00:00
|
|
|
|
*/
|
2003-08-15 04:36:53 +00:00
|
|
|
|
if (goodpart == 0) { /* didn't find anything, */
|
1999-08-07 08:07:05 +00:00
|
|
|
|
for (part = 'a'; part < 'i'; part++) /* try the compatibility partition */
|
|
|
|
|
if (part != 'c') { /* don't do the c partition */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
snprintf(np,
|
|
|
|
|
partnamelen,
|
|
|
|
|
"%c",
|
1999-08-07 08:07:05 +00:00
|
|
|
|
part);
|
|
|
|
|
drive = check_drive(partname); /* try to open it */
|
2003-06-15 01:42:01 +00:00
|
|
|
|
if (drive) { /* got something, */
|
|
|
|
|
if (drive->flags & VF_CONFIGURED) /* already read this config, */
|
|
|
|
|
log(LOG_WARNING,
|
|
|
|
|
"vinum: already read config from %s\n", /* say so */
|
|
|
|
|
drive->label.name);
|
|
|
|
|
else {
|
|
|
|
|
if (gooddrives == drives) /* ran out of entries */
|
|
|
|
|
EXPAND(drivelist, int, drives, drives); /* double the size */
|
|
|
|
|
drivelist[gooddrives] = drive->driveno; /* keep the drive index */
|
|
|
|
|
drive->flags &= ~VF_NEWBORN; /* which is no longer newly born */
|
|
|
|
|
gooddrives++;
|
2003-08-15 04:36:53 +00:00
|
|
|
|
goodpart++;
|
2003-06-15 01:42:01 +00:00
|
|
|
|
}
|
1999-08-07 08:07:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
2003-05-04 05:15:07 +00:00
|
|
|
|
Free(partname);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
|
|
|
|
if (gooddrives == 0) {
|
2001-05-22 02:32:22 +00:00
|
|
|
|
if (firsttime)
|
|
|
|
|
log(LOG_WARNING, "vinum: no drives found\n");
|
|
|
|
|
else
|
|
|
|
|
log(LOG_INFO, "vinum: no additional drives found\n");
|
2003-05-04 05:15:07 +00:00
|
|
|
|
if (malloced)
|
|
|
|
|
Free(devicename);
|
2003-05-05 05:32:52 +00:00
|
|
|
|
unlock_config();
|
1999-03-02 06:54:30 +00:00
|
|
|
|
return ENOENT;
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* We now have at least one drive open. Sort
|
|
|
|
|
* them in order of config time and merge the
|
|
|
|
|
* config info with what we have already.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-02-11 06:43:15 +00:00
|
|
|
|
qsort(drivelist, gooddrives, sizeof(int), drivecmp);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
config_text = (char *) Malloc(MAXCONFIG * 2); /* allocate buffers */
|
|
|
|
|
CHECKALLOC(config_text, "Can't allocate memory");
|
|
|
|
|
config_line = (char *) Malloc(MAXCONFIGLINE * 2); /* allocate buffers */
|
|
|
|
|
CHECKALLOC(config_line, "Can't allocate memory");
|
|
|
|
|
for (driveno = 0; driveno < gooddrives; driveno++) { /* now include the config */
|
1999-02-11 06:43:15 +00:00
|
|
|
|
drive = &DRIVE[drivelist[driveno]]; /* point to the drive */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
|
|
|
|
if (firsttime && (driveno == 0)) /* we've never configured before, */
|
1999-03-02 06:54:30 +00:00
|
|
|
|
log(LOG_INFO, "vinum: reading configuration from %s\n", drive->devicename);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
else
|
1999-03-02 06:54:30 +00:00
|
|
|
|
log(LOG_INFO, "vinum: updating configuration from %s\n", drive->devicename);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
1999-10-13 03:17:59 +00:00
|
|
|
|
if (drive->state == drive_up)
|
|
|
|
|
/* Read in both copies of the configuration information */
|
|
|
|
|
error = read_drive(drive, config_text, MAXCONFIG * 2, VINUM_CONFIG_OFFSET);
|
|
|
|
|
else {
|
|
|
|
|
error = EIO;
|
|
|
|
|
printf("vinum_scandisk: %s is %s\n", drive->devicename, drive_state(drive->state));
|
|
|
|
|
}
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
|
|
|
|
if (error != 0) {
|
1999-03-02 06:54:30 +00:00
|
|
|
|
log(LOG_ERR, "vinum: Can't read device %s, error %d\n", drive->devicename, error);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
free_drive(drive); /* give it back */
|
|
|
|
|
status = error;
|
|
|
|
|
}
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* At this point, check that the two copies
|
|
|
|
|
* are the same, and do something useful if
|
|
|
|
|
* not. In particular, consider which is
|
|
|
|
|
* newer, and what this means for the
|
|
|
|
|
* integrity of the data on the drive.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-01-21 00:35:35 +00:00
|
|
|
|
else {
|
1999-03-30 05:00:19 +00:00
|
|
|
|
vinum_conf.drives_used++; /* another drive in use */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
/* Parse the configuration, and add it to the global configuration */
|
|
|
|
|
for (cptr = config_text; *cptr != '\0';) { /* love this style(9) */
|
|
|
|
|
volatile int parse_status; /* return value from parse_config */
|
|
|
|
|
|
|
|
|
|
for (eptr = config_line; (*cptr != '\n') && (*cptr != '\0');) /* until the end of the line */
|
|
|
|
|
*eptr++ = *cptr++;
|
|
|
|
|
*eptr = '\0'; /* and delimit */
|
|
|
|
|
if (setjmp(command_fail) == 0) { /* come back here on error and continue */
|
|
|
|
|
parse_status = parse_config(config_line, &keyword_set, 1); /* parse the config line */
|
2003-05-19 02:21:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* parse_config recognizes referenced
|
|
|
|
|
* drives and builds a drive entry for
|
|
|
|
|
* them. This may expand the drive
|
|
|
|
|
* table, thus invalidating the pointer.
|
|
|
|
|
*/
|
|
|
|
|
drive = &DRIVE[drivelist[driveno]]; /* point to the drive */
|
|
|
|
|
|
1999-01-21 00:35:35 +00:00
|
|
|
|
if (parse_status < 0) { /* error in config */
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
2003-05-01 01:30:31 +00:00
|
|
|
|
* This config should have been parsed
|
|
|
|
|
* in user space. If we run into
|
|
|
|
|
* problems here, something serious is
|
|
|
|
|
* afoot. Complain and let the user
|
|
|
|
|
* snarf the config to see what's
|
|
|
|
|
* wrong.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-03-02 06:54:30 +00:00
|
|
|
|
log(LOG_ERR,
|
2000-02-29 06:11:13 +00:00
|
|
|
|
"vinum: Config error on %s, aborting integration\n",
|
2000-05-11 07:24:41 +00:00
|
|
|
|
drive->devicename);
|
1999-01-21 00:35:35 +00:00
|
|
|
|
free_drive(drive); /* give it back */
|
|
|
|
|
status = EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (*cptr == '\n')
|
|
|
|
|
cptr++; /* skip to next line */
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-19 02:21:31 +00:00
|
|
|
|
drive->flags |= VF_CONFIGURED; /* this drive's configuration is complete */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Free(config_text);
|
|
|
|
|
Free(drivelist);
|
1999-03-19 07:13:31 +00:00
|
|
|
|
vinum_conf.flags &= ~VF_READING_CONFIG; /* no longer reading from disk */
|
1999-01-21 00:35:35 +00:00
|
|
|
|
if (status != 0)
|
2000-02-29 06:11:13 +00:00
|
|
|
|
printf("vinum: couldn't read configuration");
|
|
|
|
|
else
|
|
|
|
|
updateconfig(VF_READING_CONFIG); /* update from disk config */
|
2003-05-04 05:15:07 +00:00
|
|
|
|
if (malloced)
|
|
|
|
|
Free(devicename);
|
2003-05-05 05:32:52 +00:00
|
|
|
|
unlock_config();
|
2000-02-29 06:11:13 +00:00
|
|
|
|
return status;
|
1999-01-21 00:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* Compare the modification dates of the drives, for qsort.
|
1999-01-21 00:35:35 +00:00
|
|
|
|
* Return 1 if a < b, 0 if a == b, 01 if a > b: in other
|
1999-08-14 06:26:32 +00:00
|
|
|
|
* words, sort backwards.
|
1999-01-29 01:17:54 +00:00
|
|
|
|
*/
|
1999-08-15 02:31:19 +00:00
|
|
|
|
int
|
1999-01-21 00:35:35 +00:00
|
|
|
|
drivecmp(const void *va, const void *vb)
|
|
|
|
|
{
|
1999-02-11 06:43:15 +00:00
|
|
|
|
const struct drive *a = &DRIVE[*(const int *) va];
|
|
|
|
|
const struct drive *b = &DRIVE[*(const int *) vb];
|
1999-01-21 00:35:35 +00:00
|
|
|
|
|
|
|
|
|
if ((a->label.last_update.tv_sec == b->label.last_update.tv_sec)
|
|
|
|
|
&& (a->label.last_update.tv_usec == b->label.last_update.tv_usec))
|
|
|
|
|
return 0;
|
|
|
|
|
else if ((a->label.last_update.tv_sec > b->label.last_update.tv_sec)
|
|
|
|
|
|| ((a->label.last_update.tv_sec == b->label.last_update.tv_sec)
|
|
|
|
|
&& (a->label.last_update.tv_usec > b->label.last_update.tv_usec)))
|
|
|
|
|
return -1;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
1999-08-14 06:26:32 +00:00
|
|
|
|
/* Local Variables: */
|
|
|
|
|
/* fill-column: 50 */
|
|
|
|
|
/* End: */
|