1998-12-28 04:56:24 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998
|
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
*
|
1999-08-07 08:05:46 +00:00
|
|
|
* Written by Greg Lehey
|
|
|
|
*
|
1998-12-28 04:56:24 +00:00
|
|
|
* 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-24 02:18:55 +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-03 04:51:31 +00:00
|
|
|
* $Id: vinum.c,v 1.44 2003/05/23 00:50:55 grog Exp grog $
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-05-23 01:14:35 +00:00
|
|
|
#define STATIC static /* nothing while we're testing */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#include <dev/vinum/vinumhdr.h>
|
|
|
|
#include <sys/sysproto.h> /* for sync(2) */
|
|
|
|
#ifdef VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
#include <sys/reboot.h>
|
2003-05-23 01:14:35 +00:00
|
|
|
int debug = 0; /* debug flags */
|
1999-05-02 07:59:04 +00:00
|
|
|
extern int total_malloced;
|
1999-03-31 08:41:18 +00:00
|
|
|
extern int malloccount;
|
|
|
|
extern struct mc malloced[];
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
1999-01-21 00:30:52 +00:00
|
|
|
#include <dev/vinum/request.h>
|
1998-12-28 04:56:24 +00:00
|
|
|
|
2004-02-23 08:55:13 +00:00
|
|
|
struct cdevsw vinum_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_open = vinumopen,
|
|
|
|
.d_close = vinumclose,
|
|
|
|
.d_read = physread,
|
|
|
|
.d_write = physwrite,
|
|
|
|
.d_ioctl = vinumioctl,
|
|
|
|
.d_strategy = vinumstrategy,
|
|
|
|
.d_name = "vinum",
|
|
|
|
.d_flags = D_DISK | D_NEEDGIANT
|
1998-12-28 04:56:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Called by main() during pseudo-device attachment. */
|
2003-05-01 01:28:42 +00:00
|
|
|
void vinumattach(void *);
|
1998-12-28 04:56:24 +00:00
|
|
|
STATIC int vinum_modevent(module_t mod, modeventtype_t type, void *unused);
|
2004-06-16 09:47:26 +00:00
|
|
|
STATIC void vinum_clone(void *arg, char *name, int namelen, struct cdev ** 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
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
struct _vinum_conf vinum_conf; /* configuration information */
|
|
|
|
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *vinum_daemon_dev;
|
|
|
|
struct cdev *vinum_super_dev;
|
2001-02-20 11:37:04 +00:00
|
|
|
|
2003-02-11 21:12:43 +00:00
|
|
|
static eventhandler_tag dev_clone_tag;
|
|
|
|
|
2003-05-23 01:14:35 +00:00
|
|
|
/*
|
|
|
|
* Mutexes for plex synchronization. Ideally each plex
|
|
|
|
* should have its own mutex, but the fact that the plex
|
|
|
|
* struct can move makes that very complicated. Instead,
|
|
|
|
* have plexes use share these mutexes based on modulo plex
|
|
|
|
* number.
|
|
|
|
*/
|
|
|
|
struct mtx plexmutex[PLEXMUTEXES];
|
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
/*
|
|
|
|
* Called by main() during pseudo-device attachment. All we need
|
|
|
|
* to do is allocate enough space for devices to be configured later, and
|
|
|
|
* add devsw entries.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vinumattach(void *dummy)
|
|
|
|
{
|
2003-05-04 05:13:45 +00:00
|
|
|
char *envp;
|
2003-05-23 01:14:35 +00:00
|
|
|
int i;
|
|
|
|
#define MUTEXNAMELEN 16
|
|
|
|
char mutexname[MUTEXNAMELEN];
|
|
|
|
#if PLEXMUTEXES > 10000
|
|
|
|
#error Increase size of MUTEXNAMELEN
|
|
|
|
#endif
|
2003-05-01 01:28:42 +00:00
|
|
|
/* modload should prevent multiple loads, so this is worth a panic */
|
2000-02-29 06:07:39 +00:00
|
|
|
if ((vinum_conf.flags & VF_LOADED) != 0)
|
1998-12-28 04:56:24 +00:00
|
|
|
panic("vinum: already loaded");
|
|
|
|
|
1999-03-02 06:52:11 +00:00
|
|
|
log(LOG_INFO, "vinum: loaded\n");
|
2001-05-23 05:25:45 +00:00
|
|
|
#ifdef VINUMDEBUG
|
|
|
|
vinum_conf.flags |= VF_LOADED | VF_HASDEBUG; /* we're loaded now, and we support debug */
|
|
|
|
#else
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.flags |= VF_LOADED; /* we're loaded now */
|
2001-05-23 05:25:45 +00:00
|
|
|
#endif
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:30:52 +00:00
|
|
|
daemonq = NULL; /* initialize daemon's work queue */
|
|
|
|
dqend = NULL;
|
|
|
|
|
2001-05-22 02:29:15 +00:00
|
|
|
vinum_daemon_dev = make_dev(&vinum_cdevsw,
|
2003-05-01 01:28:42 +00:00
|
|
|
VINUM_DAEMON_MINOR,
|
2001-05-22 02:29:15 +00:00
|
|
|
UID_ROOT,
|
|
|
|
GID_WHEEL,
|
|
|
|
S_IRUSR | S_IWUSR,
|
|
|
|
"vinum/controld");
|
2001-02-20 22:07:36 +00:00
|
|
|
vinum_super_dev = make_dev(&vinum_cdevsw,
|
2003-05-01 01:28:42 +00:00
|
|
|
VINUM_SUPERDEV_MINOR,
|
2001-05-22 02:29:15 +00:00
|
|
|
UID_ROOT,
|
|
|
|
GID_WHEEL,
|
|
|
|
S_IRUSR | S_IWUSR,
|
|
|
|
"vinum/control");
|
|
|
|
|
|
|
|
vinum_conf.version = VINUMVERSION; /* note what version we are */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
/* allocate space: drives... */
|
|
|
|
DRIVE = (struct drive *) Malloc(sizeof(struct drive) * INITIAL_DRIVES);
|
|
|
|
CHECKALLOC(DRIVE, "vinum: no memory\n");
|
1999-03-02 06:52:11 +00:00
|
|
|
bzero(DRIVE, sizeof(struct drive) * INITIAL_DRIVES);
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.drives_allocated = INITIAL_DRIVES; /* number of drive slots allocated */
|
|
|
|
vinum_conf.drives_used = 0; /* and number in use */
|
|
|
|
|
|
|
|
/* volumes, ... */
|
|
|
|
VOL = (struct volume *) Malloc(sizeof(struct volume) * INITIAL_VOLUMES);
|
|
|
|
CHECKALLOC(VOL, "vinum: no memory\n");
|
1999-03-02 06:52:11 +00:00
|
|
|
bzero(VOL, sizeof(struct volume) * INITIAL_VOLUMES);
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.volumes_allocated = INITIAL_VOLUMES; /* number of volume slots allocated */
|
|
|
|
vinum_conf.volumes_used = 0; /* and number in use */
|
|
|
|
|
|
|
|
/* plexes, ... */
|
|
|
|
PLEX = (struct plex *) Malloc(sizeof(struct plex) * INITIAL_PLEXES);
|
|
|
|
CHECKALLOC(PLEX, "vinum: no memory\n");
|
1999-03-02 06:52:11 +00:00
|
|
|
bzero(PLEX, sizeof(struct plex) * INITIAL_PLEXES);
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.plexes_allocated = INITIAL_PLEXES; /* number of plex slots allocated */
|
|
|
|
vinum_conf.plexes_used = 0; /* and number in use */
|
|
|
|
|
2003-05-23 01:14:35 +00:00
|
|
|
for (i = 0; i < PLEXMUTEXES; i++) {
|
|
|
|
snprintf(mutexname, MUTEXNAMELEN, "vinumplex%d", i);
|
|
|
|
mtx_init(&plexmutex[i], mutexname, "plex", MTX_DEF);
|
|
|
|
}
|
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
/* and subdisks */
|
|
|
|
SD = (struct sd *) Malloc(sizeof(struct sd) * INITIAL_SUBDISKS);
|
|
|
|
CHECKALLOC(SD, "vinum: no memory\n");
|
1999-03-02 06:52:11 +00:00
|
|
|
bzero(SD, sizeof(struct sd) * INITIAL_SUBDISKS);
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.subdisks_allocated = INITIAL_SUBDISKS; /* number of sd slots allocated */
|
|
|
|
vinum_conf.subdisks_used = 0; /* and number in use */
|
2003-02-11 21:12:43 +00:00
|
|
|
dev_clone_tag = EVENTHANDLER_REGISTER(dev_clone, vinum_clone, 0, 1000);
|
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
|
|
|
|
|
|
|
/*
|
2003-05-01 01:28:42 +00:00
|
|
|
* See if the loader has passed us any of the autostart
|
|
|
|
* options.
|
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
|
|
|
*/
|
2003-05-04 05:13:45 +00:00
|
|
|
envp = NULL;
|
|
|
|
if ((envp = getenv("vinum.autostart")) != NULL) { /* start all drives now */
|
|
|
|
vinum_scandisk(NULL);
|
|
|
|
freeenv(envp);
|
|
|
|
} else if ((envp = getenv("vinum.drives")) != NULL) {
|
|
|
|
vinum_scandisk(envp);
|
|
|
|
freeenv(envp);
|
2003-05-01 01:28:42 +00:00
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-01-29 01:16:18 +00:00
|
|
|
/*
|
1999-03-13 07:22:00 +00:00
|
|
|
* Check if we have anything open. If confopen is != 0,
|
|
|
|
* that goes for the super device as well, otherwise
|
|
|
|
* only for volumes.
|
|
|
|
*
|
|
|
|
* Return 0 if not inactive, 1 if inactive.
|
1999-01-29 01:16:18 +00:00
|
|
|
*/
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
1999-03-13 07:22:00 +00:00
|
|
|
vinum_inactive(int confopen)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int can_do = 1; /* assume we can do it */
|
|
|
|
|
1999-03-13 07:22:00 +00:00
|
|
|
if (confopen && (vinum_conf.flags & VF_OPEN)) /* open by vinum(8)? */
|
1999-03-02 06:52:11 +00:00
|
|
|
return 0; /* can't do it while we're open */
|
1998-12-28 04:56:24 +00:00
|
|
|
lock_config();
|
1999-03-30 04:59:32 +00:00
|
|
|
for (i = 0; i < vinum_conf.volumes_allocated; i++) {
|
|
|
|
if ((VOL[i].state > volume_down)
|
|
|
|
&& (VOL[i].flags & VF_OPEN)) { /* volume is open */
|
1998-12-28 04:56:24 +00:00
|
|
|
can_do = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlock_config();
|
|
|
|
return can_do;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:16:18 +00:00
|
|
|
/*
|
|
|
|
* Free all structures.
|
1998-12-28 04:56:24 +00:00
|
|
|
* If cleardrive is 0, save the configuration; otherwise
|
|
|
|
* remove the configuration from the drive.
|
|
|
|
*
|
|
|
|
* Before coming here, ensure that no volumes are open.
|
|
|
|
*/
|
1999-08-24 02:18:55 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
free_vinum(int cleardrive)
|
|
|
|
{
|
|
|
|
int i;
|
1999-03-30 04:59:32 +00:00
|
|
|
int drives_allocated = vinum_conf.drives_allocated;
|
1999-03-19 07:08:40 +00:00
|
|
|
|
2003-05-05 05:28:15 +00:00
|
|
|
while ((vinum_conf.flags & (VF_STOPPING | VF_DAEMONOPEN))
|
|
|
|
== (VF_STOPPING | VF_DAEMONOPEN)) { /* at least one daemon open, we're stopping */
|
|
|
|
queue_daemon_request(daemonrq_return, (union daemoninfo) 0); /* stop the daemon */
|
|
|
|
tsleep(&vinumclose, PUSER, "vstop", 1); /* and wait for it */
|
|
|
|
}
|
1999-03-19 07:08:40 +00:00
|
|
|
if (DRIVE != NULL) {
|
|
|
|
if (cleardrive) { /* remove the vinum config */
|
1999-03-30 04:59:32 +00:00
|
|
|
for (i = 0; i < drives_allocated; i++)
|
1999-03-19 07:08:40 +00:00
|
|
|
remove_drive(i); /* remove the drive */
|
|
|
|
} else { /* keep the config */
|
1999-03-30 04:59:32 +00:00
|
|
|
for (i = 0; i < drives_allocated; i++)
|
1998-12-28 04:56:24 +00:00
|
|
|
free_drive(&DRIVE[i]); /* close files and things */
|
|
|
|
}
|
1999-03-19 07:08:40 +00:00
|
|
|
Free(DRIVE);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
2001-02-20 11:37:04 +00:00
|
|
|
if (SD != NULL) {
|
|
|
|
for (i = 0; i < vinum_conf.subdisks_allocated; i++) {
|
2001-05-22 02:29:15 +00:00
|
|
|
struct sd *sd = &SD[i];
|
2001-02-20 11:37:04 +00:00
|
|
|
|
|
|
|
if (sd->state != sd_unallocated)
|
|
|
|
free_sd(i);
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
Free(SD);
|
2001-02-20 11:37:04 +00:00
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
if (PLEX != NULL) {
|
1999-03-30 04:59:32 +00:00
|
|
|
for (i = 0; i < vinum_conf.plexes_allocated; i++) {
|
2001-05-22 02:29:15 +00:00
|
|
|
struct plex *plex = &PLEX[i];
|
1998-12-28 04:56:24 +00:00
|
|
|
|
2001-02-20 11:37:04 +00:00
|
|
|
if (plex->state != plex_unallocated) /* we have real data there */
|
|
|
|
free_plex(i);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
Free(PLEX);
|
|
|
|
}
|
2001-02-20 11:37:04 +00:00
|
|
|
if (VOL != NULL) {
|
|
|
|
for (i = 0; i < vinum_conf.volumes_allocated; i++) {
|
2001-05-22 02:29:15 +00:00
|
|
|
struct volume *volume = &VOL[i];
|
2001-02-20 11:37:04 +00:00
|
|
|
|
|
|
|
if (volume->state != volume_unallocated)
|
|
|
|
free_volume(i);
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
Free(VOL);
|
2001-02-20 11:37:04 +00:00
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
bzero(&vinum_conf, sizeof(vinum_conf));
|
2003-05-01 01:28:42 +00:00
|
|
|
vinum_conf.version = VINUMVERSION; /* reinstate version number */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-08-24 02:18:55 +00:00
|
|
|
STATIC int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_modevent(module_t mod, modeventtype_t type, void *unused)
|
|
|
|
{
|
|
|
|
struct sync_args dummyarg =
|
|
|
|
{0};
|
2003-05-23 01:14:35 +00:00
|
|
|
int i;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
vinumattach(NULL);
|
|
|
|
return 0; /* OK */
|
|
|
|
case MOD_UNLOAD:
|
1999-03-13 07:22:00 +00:00
|
|
|
if (!vinum_inactive(1)) /* is anything open? */
|
1999-03-02 06:52:11 +00:00
|
|
|
return EBUSY; /* yes, we can't do it */
|
|
|
|
vinum_conf.flags |= VF_STOPPING; /* note that we want to stop */
|
2001-09-12 08:38:13 +00:00
|
|
|
sync(curthread, &dummyarg); /* write out buffers */
|
1999-03-02 06:52:11 +00:00
|
|
|
free_vinum(0); /* clean up */
|
1999-03-31 08:41:18 +00:00
|
|
|
#ifdef VINUMDEBUG
|
|
|
|
if (total_malloced) {
|
|
|
|
int i;
|
1999-04-17 04:15:50 +00:00
|
|
|
#ifdef INVARIANTS
|
1999-04-05 04:02:09 +00:00
|
|
|
int *poke;
|
1999-04-17 04:15:50 +00:00
|
|
|
#endif
|
1999-04-05 04:02:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < malloccount; i++) {
|
1999-05-02 07:59:04 +00:00
|
|
|
if (debug & DEBUG_WARNINGS) /* want to hear about them */
|
1999-04-05 04:02:09 +00:00
|
|
|
log(LOG_WARNING,
|
|
|
|
"vinum: exiting with %d bytes malloced from %s:%d\n",
|
|
|
|
malloced[i].size,
|
|
|
|
malloced[i].file,
|
|
|
|
malloced[i].line);
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
poke = &((int *) malloced[i].address)
|
|
|
|
[malloced[i].size / (2 * sizeof(int))]; /* middle of the area */
|
|
|
|
if (*poke == 0xdeadc0de) /* already freed */
|
|
|
|
log(LOG_ERR,
|
|
|
|
"vinum: exiting with malloc table inconsistency at %p from %s:%d\n",
|
|
|
|
malloced[i].address,
|
|
|
|
malloced[i].file,
|
|
|
|
malloced[i].line);
|
|
|
|
#endif
|
|
|
|
Free(malloced[i].address);
|
|
|
|
}
|
1999-03-31 08:41:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-05-22 02:29:15 +00:00
|
|
|
destroy_dev(vinum_daemon_dev); /* daemon device */
|
2001-02-20 11:37:04 +00:00
|
|
|
destroy_dev(vinum_super_dev);
|
2003-05-23 01:14:35 +00:00
|
|
|
for (i = 0; i < PLEXMUTEXES; i++)
|
|
|
|
mtx_destroy(&plexmutex[i]);
|
1999-03-02 06:52:11 +00:00
|
|
|
log(LOG_INFO, "vinum: unloaded\n"); /* tell the world */
|
2003-06-03 04:51:31 +00:00
|
|
|
EVENTHANDLER_DEREGISTER(dev_clone, dev_clone_tag);
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-13 05:55:43 +00:00
|
|
|
static moduledata_t vinum_mod =
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
"vinum",
|
1999-03-18 23:26:22 +00:00
|
|
|
(modeventhand_t) vinum_modevent,
|
1998-12-28 04:56:24 +00:00
|
|
|
0
|
|
|
|
};
|
2003-06-03 04:51:31 +00:00
|
|
|
DECLARE_MODULE(vinum, vinum_mod, SI_SUB_RAID, SI_ORDER_MIDDLE);
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-03-18 23:26:22 +00:00
|
|
|
/* Open a vinum object */
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
vinumopen(struct cdev *dev,
|
1998-12-28 04:56:24 +00:00
|
|
|
int flags,
|
|
|
|
int fmt,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
unsigned int index;
|
|
|
|
struct volume *vol;
|
|
|
|
struct plex *plex;
|
|
|
|
struct sd *sd;
|
1999-08-07 08:05:46 +00:00
|
|
|
int devminor; /* minor number */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-07-22 08:40:37 +00:00
|
|
|
devminor = minor(dev);
|
1998-12-28 04:56:24 +00:00
|
|
|
error = 0;
|
|
|
|
/* First, decide what we're looking at */
|
1999-05-15 05:49:21 +00:00
|
|
|
switch (DEVTYPE(dev)) {
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_VOLUME_TYPE:
|
2003-05-01 01:28:42 +00:00
|
|
|
/*
|
|
|
|
* The super device and daemon device are the last two
|
|
|
|
* volume numbers, so check for them first.
|
|
|
|
*/
|
|
|
|
if ((devminor == VINUM_DAEMON_MINOR) /* daemon device */
|
|
|
|
||(devminor == VINUM_SUPERDEV_MINOR)) { /* or normal super device */
|
|
|
|
error = suser(td); /* are we root? */
|
|
|
|
|
|
|
|
if (error == 0) { /* yes, can do */
|
|
|
|
if (devminor == VINUM_DAEMON_MINOR) /* daemon device */
|
|
|
|
vinum_conf.flags |= VF_DAEMONOPEN; /* we're open */
|
|
|
|
else /* superdev */
|
|
|
|
vinum_conf.flags |= VF_OPEN; /* we're open */
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/* Must be a real volume. Check. */
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Volno(dev);
|
1999-03-30 04:59:32 +00:00
|
|
|
if (index >= vinum_conf.volumes_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
|
|
|
vol = &VOL[index];
|
|
|
|
|
|
|
|
switch (vol->state) {
|
|
|
|
case volume_unallocated:
|
|
|
|
case volume_uninit:
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
case volume_up:
|
1999-03-02 06:52:11 +00:00
|
|
|
vol->flags |= VF_OPEN; /* note we're open */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case volume_down:
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VINUM_PLEX_TYPE:
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Plexno(dev); /* get plex index in vinum_conf */
|
1999-03-30 04:59:32 +00:00
|
|
|
if (index >= vinum_conf.plexes_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
|
|
|
plex = &PLEX[index];
|
|
|
|
|
|
|
|
switch (plex->state) {
|
|
|
|
case plex_unallocated:
|
2003-05-01 01:28:42 +00:00
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
case plex_referenced:
|
1998-12-28 04:56:24 +00:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
default:
|
1999-03-02 06:52:11 +00:00
|
|
|
plex->flags |= VF_OPEN; /* note we're open */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VINUM_SD_TYPE:
|
2003-05-01 01:28:42 +00:00
|
|
|
case VINUM_SD2_TYPE:
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Sdno(dev); /* get the subdisk number */
|
2003-05-01 01:28:42 +00:00
|
|
|
if (index >= vinum_conf.subdisks_allocated) /* not a valid SD entry */
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
|
|
|
sd = &SD[index];
|
|
|
|
|
1999-01-29 01:16:18 +00:00
|
|
|
/*
|
2003-05-01 01:28:42 +00:00
|
|
|
* Opening a subdisk is always a special operation, so
|
|
|
|
* we ignore the state as long as it represents a real
|
|
|
|
* subdisk.
|
1999-01-29 01:16:18 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
switch (sd->state) {
|
|
|
|
case sd_unallocated:
|
2003-05-01 01:28:42 +00:00
|
|
|
return ENXIO;
|
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
case sd_uninit:
|
2003-05-01 01:28:42 +00:00
|
|
|
case sd_referenced:
|
1998-12-28 04:56:24 +00:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
default:
|
1999-03-02 06:52:11 +00:00
|
|
|
sd->flags |= VF_OPEN; /* note we're open */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-05-01 01:28:42 +00:00
|
|
|
return 0; /* to keep the compiler happy */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
vinumclose(struct cdev *dev,
|
1998-12-28 04:56:24 +00:00
|
|
|
int flags,
|
|
|
|
int fmt,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
unsigned int index;
|
|
|
|
struct volume *vol;
|
1999-07-22 08:40:37 +00:00
|
|
|
int devminor;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-07-22 08:40:37 +00:00
|
|
|
devminor = minor(dev);
|
1998-12-28 04:56:24 +00:00
|
|
|
/* First, decide what we're looking at */
|
1999-05-15 05:49:21 +00:00
|
|
|
switch (DEVTYPE(dev)) {
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_VOLUME_TYPE:
|
2003-05-01 01:28:42 +00:00
|
|
|
/*
|
|
|
|
* The super device and daemon device are the last two
|
|
|
|
* volume numbers, so check for them first.
|
|
|
|
*/
|
|
|
|
if ((devminor == VINUM_DAEMON_MINOR) /* daemon device */
|
|
|
|
||(devminor == VINUM_SUPERDEV_MINOR)) { /* or normal super device */
|
|
|
|
/*
|
|
|
|
* don't worry about whether we're root:
|
|
|
|
* nobody else would get this far.
|
|
|
|
*/
|
|
|
|
if (devminor == VINUM_SUPERDEV_MINOR) /* normal superdev */
|
|
|
|
vinum_conf.flags &= ~VF_OPEN; /* no longer open */
|
|
|
|
else { /* the daemon device */
|
|
|
|
vinum_conf.flags &= ~VF_DAEMONOPEN; /* no longer open */
|
|
|
|
if (vinum_conf.flags & VF_STOPPING) /* we're trying to stop, */
|
|
|
|
wakeup(&vinumclose); /* we can continue now */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Real volume */
|
|
|
|
index = Volno(dev);
|
1999-03-30 04:59:32 +00:00
|
|
|
if (index >= vinum_conf.volumes_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
|
|
|
vol = &VOL[index];
|
|
|
|
|
|
|
|
switch (vol->state) {
|
|
|
|
case volume_unallocated:
|
|
|
|
case volume_uninit:
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
case volume_up:
|
1999-03-02 06:52:11 +00:00
|
|
|
vol->flags &= ~VF_OPEN; /* reset our flags */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case volume_down:
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VINUM_PLEX_TYPE:
|
1999-03-30 04:59:32 +00:00
|
|
|
if (Volno(dev) >= vinum_conf.volumes_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO;
|
2003-12-15 00:42:03 +00:00
|
|
|
index = Plexno (dev);
|
|
|
|
if (index >= vinum_conf.plexes_allocated) /* no such plex */
|
|
|
|
return ENXIO;
|
|
|
|
PLEX [index].flags &= ~VF_OPEN; /* no longer open */
|
|
|
|
return 0;
|
1999-08-24 02:18:55 +00:00
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_SD_TYPE:
|
1999-03-30 04:59:32 +00:00
|
|
|
if ((Volno(dev) >= vinum_conf.volumes_allocated) || /* no such volume */
|
|
|
|
(Plexno(dev) >= vinum_conf.plexes_allocated)) /* or no such plex */
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
2003-12-15 00:42:03 +00:00
|
|
|
index = Sdno (dev);
|
|
|
|
if (index >= vinum_conf.subdisks_allocated) /* no such sd */
|
|
|
|
return ENXIO;
|
|
|
|
SD [index].flags &= ~VF_OPEN; /* no longer open */
|
|
|
|
return 0;
|
|
|
|
|
1999-08-24 02:18:55 +00:00
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
default:
|
|
|
|
return ENODEV; /* don't know what to do with these */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void
|
2004-06-16 09:47:26 +00:00
|
|
|
vinum_clone(void *arg, char *name, int namelen, struct cdev ** 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
|
|
|
{
|
2003-05-01 01:28:42 +00:00
|
|
|
struct volume *vol;
|
|
|
|
int i;
|
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
|
|
|
|
2004-06-17 17:16:53 +00:00
|
|
|
if (*dev != NULL)
|
2003-05-01 01:28:42 +00:00
|
|
|
return;
|
|
|
|
if (strncmp(name, "vinum/", sizeof("vinum/") - 1) != 0)
|
|
|
|
return;
|
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
|
|
|
|
2003-05-01 01:28:42 +00:00
|
|
|
name += sizeof("vinum/") - 1;
|
|
|
|
if ((i = find_volume(name, 0)) == -1)
|
|
|
|
return;
|
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
|
|
|
|
2003-05-01 01:28:42 +00:00
|
|
|
vol = &VOL[i];
|
|
|
|
*dev = vol->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
|
|
|
}
|
|
|
|
|
2003-05-01 01:28:42 +00:00
|
|
|
|
1999-08-29 01:41:53 +00:00
|
|
|
/* Local Variables: */
|
2003-05-01 01:28:42 +00:00
|
|
|
/* fill-column: 60 */
|
1999-08-29 01:41:53 +00:00
|
|
|
/* End: */
|