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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
|
1999-03-02 06:52:11 +00:00
|
|
|
#define STATIC static /* nothing while we're testing XXX */
|
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>
|
|
|
|
int debug = 0;
|
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
|
|
|
|
|
|
|
STATIC struct cdevsw vinum_cdevsw =
|
|
|
|
{
|
1999-05-07 08:07:09 +00:00
|
|
|
vinumopen, vinumclose, physread, physwrite,
|
1999-09-28 22:42:06 +00:00
|
|
|
vinumioctl, seltrue, nommap, vinumstrategy,
|
|
|
|
"vinum", CDEV_MAJOR, vinumdump, vinumsize,
|
1999-09-25 18:24:47 +00:00
|
|
|
D_DISK, BDEV_MAJOR
|
1998-12-28 04:56:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Called by main() during pseudo-device attachment. */
|
|
|
|
STATIC void vinumattach(void *);
|
|
|
|
|
|
|
|
#ifndef ACTUALLY_LKM_NOT_KERNEL
|
|
|
|
STATIC int vinum_modevent(module_t mod, modeventtype_t type, void *unused);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct _vinum_conf vinum_conf; /* configuration information */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
/* modload should prevent multiple loads, so this is worth a panic */
|
|
|
|
if ((vinum_conf.flags & VF_LOADED) != NULL)
|
|
|
|
panic("vinum: already loaded");
|
|
|
|
|
1999-03-02 06:52:11 +00:00
|
|
|
log(LOG_INFO, "vinum: loaded\n");
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.flags |= VF_LOADED; /* we're loaded now */
|
|
|
|
|
1999-01-21 00:30:52 +00:00
|
|
|
daemonq = NULL; /* initialize daemon's work queue */
|
|
|
|
dqend = NULL;
|
|
|
|
|
1999-06-22 05:36:13 +00:00
|
|
|
cdevsw_add(&vinum_cdevsw); /* add the cdevsw entry */
|
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 */
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
1999-03-02 06:52:11 +00:00
|
|
|
while ((vinum_conf.flags & (VF_STOPPING | VF_DAEMONOPEN))
|
|
|
|
== (VF_STOPPING | VF_DAEMONOPEN)) { /* at least one daemon open, we're stopping */
|
1999-03-31 08:41:18 +00:00
|
|
|
queue_daemon_request(daemonrq_return, (union daemoninfo) NULL); /* stop the daemon */
|
|
|
|
tsleep(&vinumclose, PUSER, "vstop", 1); /* and wait for it */
|
1999-03-02 06:52:11 +00:00
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
if (SD != NULL)
|
|
|
|
Free(SD);
|
|
|
|
if (PLEX != NULL) {
|
1999-03-30 04:59:32 +00:00
|
|
|
for (i = 0; i < vinum_conf.plexes_allocated; i++) {
|
1998-12-28 04:56:24 +00:00
|
|
|
struct plex *plex = &vinum_conf.plex[i];
|
|
|
|
|
|
|
|
if (plex->state != plex_unallocated) { /* we have real data there */
|
|
|
|
if (plex->sdnos)
|
|
|
|
Free(plex->sdnos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Free(PLEX);
|
|
|
|
}
|
|
|
|
if (VOL != NULL)
|
|
|
|
Free(VOL);
|
|
|
|
bzero(&vinum_conf, sizeof(vinum_conf));
|
|
|
|
}
|
|
|
|
|
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};
|
|
|
|
|
|
|
|
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 */
|
1998-12-28 04:56:24 +00:00
|
|
|
sync(curproc, &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
|
1999-06-29 04:07:55 +00:00
|
|
|
cdevsw_remove(&vinum_cdevsw);
|
1999-03-02 06:52:11 +00:00
|
|
|
log(LOG_INFO, "vinum: unloaded\n"); /* tell the world */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
moduledata_t vinum_mod =
|
|
|
|
{
|
|
|
|
"vinum",
|
1999-03-18 23:26:22 +00:00
|
|
|
(modeventhand_t) vinum_modevent,
|
1998-12-28 04:56:24 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(vinum, vinum_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-03-18 23:26:22 +00:00
|
|
|
/* Open a vinum object */
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinumopen(dev_t dev,
|
|
|
|
int flags,
|
|
|
|
int fmt,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
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:
|
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-03-30 04:59:32 +00:00
|
|
|
if (Volno(dev) >= vinum_conf.volumes_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO;
|
1999-08-14 06:22:15 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case VINUM_RAWPLEX_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) {
|
1999-03-30 04:59:32 +00:00
|
|
|
case plex_referenced:
|
1998-12-28 04:56:24 +00:00
|
|
|
case plex_unallocated:
|
|
|
|
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:
|
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 */
|
1999-08-07 08:05:46 +00:00
|
|
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case VINUM_RAWSD_TYPE:
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Sdno(dev); /* get the subdisk number */
|
1999-03-30 04:59:32 +00:00
|
|
|
if ((index >= vinum_conf.subdisks_allocated) /* not a valid SD entry */
|
1999-03-31 08:41:18 +00:00
|
|
|
||(SD[index].state < sd_init)) /* or SD is not real */
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
|
|
|
sd = &SD[index];
|
|
|
|
|
1999-01-29 01:16:18 +00:00
|
|
|
/*
|
1999-08-24 02:18:55 +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:
|
|
|
|
case sd_uninit:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VINUM_SUPERDEV_TYPE:
|
1999-05-02 07:59:04 +00:00
|
|
|
error = suser(p); /* are we root? */
|
1999-03-02 06:52:11 +00:00
|
|
|
if (error == 0) { /* yes, can do */
|
1999-07-22 08:40:37 +00:00
|
|
|
if (devminor == VINUM_DAEMON_DEV) /* daemon device */
|
1999-03-02 06:52:11 +00:00
|
|
|
vinum_conf.flags |= VF_DAEMONOPEN; /* we're open */
|
1999-07-22 08:40:37 +00:00
|
|
|
else if (devminor == VINUM_SUPERDEV)
|
1999-03-02 06:52:11 +00:00
|
|
|
vinum_conf.flags |= VF_OPEN; /* we're open */
|
1999-03-19 07:08:40 +00:00
|
|
|
else
|
|
|
|
error = ENODEV; /* nothing, maybe a debug mismatch */
|
1999-03-02 06:52:11 +00:00
|
|
|
}
|
1999-01-29 01:16:18 +00:00
|
|
|
return error;
|
1999-03-02 06:52:11 +00:00
|
|
|
|
1999-08-07 08:05:46 +00:00
|
|
|
/* Vinum drives are disks. We already have a disk
|
|
|
|
* driver, so don't handle them here */
|
|
|
|
case VINUM_DRIVE_TYPE:
|
|
|
|
default:
|
|
|
|
return ENODEV; /* don't know what to do with these */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinumclose(dev_t dev,
|
|
|
|
int flags,
|
|
|
|
int fmt,
|
|
|
|
struct proc *p)
|
|
|
|
{
|
|
|
|
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);
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Volno(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:
|
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;
|
1999-08-24 02:18:55 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case VINUM_RAWPLEX_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 */
|
1999-03-02 06:52:11 +00:00
|
|
|
PLEX[index].flags &= ~VF_OPEN; /* reset our flags */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
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 */
|
1999-08-24 02:18:55 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case VINUM_RAWSD_TYPE:
|
1999-01-21 00:30:52 +00:00
|
|
|
index = Sdno(dev); /* get the subdisk number */
|
1999-03-30 04:59:32 +00:00
|
|
|
if (index >= vinum_conf.subdisks_allocated)
|
1998-12-28 04:56:24 +00:00
|
|
|
return ENXIO; /* no such device */
|
1999-03-02 06:52:11 +00:00
|
|
|
SD[index].flags &= ~VF_OPEN; /* reset our flags */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case VINUM_SUPERDEV_TYPE:
|
1999-01-29 01:16:18 +00:00
|
|
|
/*
|
|
|
|
* don't worry about whether we're root:
|
|
|
|
* nobody else would get this far.
|
|
|
|
*/
|
1999-07-22 08:40:37 +00:00
|
|
|
if (devminor == VINUM_SUPERDEV) /* normal superdev */
|
1999-03-02 06:52:11 +00:00
|
|
|
vinum_conf.flags &= ~VF_OPEN; /* no longer open */
|
1999-07-22 08:40:37 +00:00
|
|
|
else if (devminor == VINUM_DAEMON_DEV) { /* the daemon device */
|
1999-03-02 06:52:11 +00:00
|
|
|
vinum_conf.flags &= ~VF_DAEMONOPEN; /* no longer open */
|
|
|
|
if (vinum_conf.flags & VF_STOPPING) /* we're stopping, */
|
|
|
|
wakeup(&vinumclose); /* we can continue stopping now */
|
|
|
|
}
|
|
|
|
return 0;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
case VINUM_DRIVE_TYPE:
|
|
|
|
default:
|
|
|
|
return ENODEV; /* don't know what to do with these */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* size routine */
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinumsize(dev_t dev)
|
|
|
|
{
|
|
|
|
struct volume *vol;
|
|
|
|
int size;
|
|
|
|
|
1999-01-21 00:30:52 +00:00
|
|
|
vol = &VOL[Volno(dev)];
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
if (vol->state == volume_up)
|
|
|
|
size = vol->size;
|
|
|
|
else
|
|
|
|
return 0; /* err on the size of conservatism */
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
1999-08-24 02:18:55 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinumdump(dev_t dev)
|
|
|
|
{
|
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
|
|
|
}
|
1999-08-29 01:41:53 +00:00
|
|
|
/* Local Variables: */
|
|
|
|
/* fill-column: 50 */
|
|
|
|
/* End: */
|