1998-12-28 04:56:24 +00:00
|
|
|
/*-
|
1999-08-07 08:14:01 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999
|
1998-12-28 04:56:24 +00:00
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
*
|
1999-08-07 08:14:01 +00:00
|
|
|
* Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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-07 08:14:01 +00:00
|
|
|
* $Id: vinumstate.c,v 2.12 1999/07/05 01:36:48 grog Exp grog $
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#include <dev/vinum/vinumhdr.h>
|
|
|
|
#include <dev/vinum/request.h>
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
/* Update drive state */
|
|
|
|
/* Return 1 if the state changes, otherwise 0 */
|
|
|
|
int
|
1999-01-21 00:40:32 +00:00
|
|
|
set_drive_state(int driveno, enum drivestate newstate, enum setstateflags flags)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
struct drive *drive = &DRIVE[driveno];
|
|
|
|
int oldstate = drive->state;
|
|
|
|
int sdno;
|
|
|
|
|
|
|
|
if (drive->state == drive_unallocated) /* no drive to do anything with, */
|
|
|
|
return 0;
|
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
if (newstate == oldstate) /* don't change it if it's not different */
|
|
|
|
return 1; /* all OK */
|
|
|
|
if ((newstate == drive_down) /* the drive's going down */
|
|
|
|
&&(!(flags & setstate_force))
|
|
|
|
&& (drive->opencount != 0)) /* we can't do it */
|
|
|
|
return 0; /* don't do it */
|
|
|
|
drive->state = newstate; /* set the state */
|
|
|
|
if (drive->label.name[0] != '\0') /* we have a name, */
|
|
|
|
log(LOG_INFO,
|
|
|
|
"vinum: drive %s is %s\n",
|
|
|
|
drive->label.name,
|
|
|
|
drive_state(drive->state));
|
|
|
|
if ((drive->state == drive_up)
|
|
|
|
&& (drive->vp == NULL)) /* should be open, but we're not */
|
|
|
|
init_drive(drive, 1); /* which changes the state again */
|
|
|
|
if (newstate < drive_up) /* drive going down, */
|
|
|
|
queue_daemon_request(daemonrq_closedrive, /* get the daemon to close it */
|
|
|
|
(union daemoninfo) drive);
|
|
|
|
if (newstate != oldstate) { /* state has changed */
|
|
|
|
for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { /* find this drive's subdisks */
|
|
|
|
if ((SD[sdno].state >= sd_referenced)
|
|
|
|
&& (SD[sdno].driveno == driveno)) /* belongs to this drive */
|
|
|
|
update_sd_state(sdno); /* update the state */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-14 06:30:56 +00:00
|
|
|
if ((flags & setstate_configuring) == 0) /* configuring? */
|
|
|
|
save_config(); /* no: save the updated configuration now */
|
|
|
|
return 1;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Try to set the subdisk state. Return 1 if state changed to
|
1998-12-28 04:56:24 +00:00
|
|
|
* what we wanted, -1 if it changed to something else, and 0
|
|
|
|
* if no change.
|
|
|
|
*
|
1999-07-02 07:57:28 +00:00
|
|
|
* This routine is called both from the user (up, down states only)
|
|
|
|
* and internally.
|
|
|
|
*
|
|
|
|
* The setstate_force bit in the flags enables the state change even
|
|
|
|
* if it could be dangerous to data consistency. It shouldn't allow
|
|
|
|
* nonsense.
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
int
|
1999-01-21 00:40:32 +00:00
|
|
|
set_sd_state(int sdno, enum sdstate newstate, enum setstateflags flags)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
struct sd *sd = &SD[sdno];
|
1999-01-21 00:40:32 +00:00
|
|
|
struct plex *plex;
|
|
|
|
struct volume *vol;
|
1998-12-28 04:56:24 +00:00
|
|
|
int oldstate = sd->state;
|
|
|
|
int status = 1; /* status to return */
|
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
if (newstate == oldstate) /* already there, */
|
|
|
|
return 1;
|
|
|
|
else if (sd->state == sd_unallocated) /* no subdisk to do anything with, */
|
|
|
|
return 0; /* can't do it */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
if (sd->driveoffset < 0) { /* not allocated space */
|
|
|
|
sd->state = sd_down;
|
1999-01-21 00:40:32 +00:00
|
|
|
if (newstate != sd_down) {
|
|
|
|
if (sd->plexno >= 0)
|
|
|
|
sdstatemap(&PLEX[sd->plexno]); /* count up subdisks */
|
1998-12-28 04:56:24 +00:00
|
|
|
return -1;
|
1999-01-21 00:40:32 +00:00
|
|
|
}
|
1999-08-14 06:30:56 +00:00
|
|
|
} else { /* space allocated */
|
1999-01-21 00:40:32 +00:00
|
|
|
switch (newstate) {
|
1999-03-02 06:57:08 +00:00
|
|
|
case sd_down: /* take it down? */
|
|
|
|
/*
|
|
|
|
* If we're attached to a plex, and we're
|
|
|
|
* not reborn, we won't go down without
|
|
|
|
* use of force.
|
|
|
|
*/
|
|
|
|
if ((!flags & setstate_force)
|
|
|
|
&& (sd->plexno >= 0)
|
|
|
|
&& (sd->state != sd_reborn))
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0; /* don't do it */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_up:
|
|
|
|
if (DRIVE[sd->driveno].state != drive_up) /* can't bring the sd up if the drive isn't, */
|
|
|
|
return 0; /* not even by force */
|
1999-07-02 07:57:28 +00:00
|
|
|
if (flags & setstate_force) /* forcing it, */
|
|
|
|
break; /* just do it, and damn the consequences */
|
1998-12-28 04:56:24 +00:00
|
|
|
switch (sd->state) {
|
|
|
|
case sd_crashed:
|
1999-05-02 07:50:09 +00:00
|
|
|
case sd_reborn:
|
1998-12-28 04:56:24 +00:00
|
|
|
case sd_down: /* been down, no data lost */
|
1999-03-02 06:57:08 +00:00
|
|
|
/*
|
|
|
|
* If we're associated with a plex, and
|
|
|
|
* the plex isn't up, or we're the only
|
|
|
|
* subdisk in the plex, we can do it
|
|
|
|
*/
|
|
|
|
if ((sd->plexno >= 0)
|
|
|
|
&& (((PLEX[sd->plexno].state < plex_firstup)
|
|
|
|
|| (PLEX[sd->plexno].subdisks > 1))))
|
1999-01-21 00:40:32 +00:00
|
|
|
break; /* do it */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* XXX Get this right: make sure that other plexes in
|
1998-12-28 04:56:24 +00:00
|
|
|
* the volume cover this address space, otherwise
|
1999-01-21 00:40:32 +00:00
|
|
|
* we make this one sd_up.
|
|
|
|
*
|
|
|
|
* Do we even want this any more?
|
|
|
|
*/
|
1999-05-02 07:50:09 +00:00
|
|
|
if (oldstate != sd_reborn) {
|
|
|
|
sd->state = sd_reborn; /* here it is again */
|
|
|
|
log(LOG_INFO,
|
|
|
|
"vinum: subdisk %s is %s, not %s\n",
|
|
|
|
sd->name,
|
|
|
|
sd_state(sd->state),
|
|
|
|
sd_state(newstate));
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
status = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_init: /* brand new */
|
|
|
|
if (flags & setstate_configuring) /* we're doing this while configuring */
|
|
|
|
break;
|
1999-01-21 00:40:32 +00:00
|
|
|
/* otherwise it's like being empty */
|
|
|
|
/* FALLTHROUGH */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
case sd_initializing:
|
1998-12-28 04:56:24 +00:00
|
|
|
case sd_empty:
|
1999-03-02 06:57:08 +00:00
|
|
|
/*
|
1999-07-02 07:57:28 +00:00
|
|
|
* If we're associated with a plex which is down, or which is
|
|
|
|
* the only one in the volume, and we're not a RAID-5 plex, we
|
|
|
|
* can come up without being inconsistent. Internally, we use
|
|
|
|
* the force flag to bring up a RAID-5 plex after
|
|
|
|
* initialization.
|
1999-03-02 06:57:08 +00:00
|
|
|
*/
|
|
|
|
if ((sd->plexno >= 0)
|
1999-03-28 08:54:48 +00:00
|
|
|
&& ((PLEX[sd->plexno].organization != plex_raid5)
|
|
|
|
|| (flags & setstate_force))
|
1999-03-02 06:57:08 +00:00
|
|
|
&& (((PLEX[sd->plexno].state < plex_firstup)
|
|
|
|
|| (PLEX[sd->plexno].subdisks > 1))))
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
1999-01-21 00:40:32 +00:00
|
|
|
/* Otherwise it's just out of date */
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case sd_stale: /* out of date info, need reviving */
|
|
|
|
case sd_obsolete:
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* 1. If the subdisk is not part of a plex, bring it up, don't revive.
|
|
|
|
*
|
1999-01-21 00:40:32 +00:00
|
|
|
* 2. If the subdisk is part of a one-plex volume or an unattached plex,
|
|
|
|
* and it's not RAID-5, we *can't revive*. The subdisk doesn't
|
|
|
|
* change its state.
|
1999-03-28 08:54:48 +00:00
|
|
|
*
|
1999-01-21 00:40:32 +00:00
|
|
|
* 3. If the subdisk is part of a one-plex volume or an unattached plex,
|
|
|
|
* and it's RAID-5, but more than one subdisk is down, we *still
|
|
|
|
* can't revive*. The subdisk doesn't change its state.
|
1999-03-28 08:54:48 +00:00
|
|
|
*
|
1999-01-21 00:40:32 +00:00
|
|
|
* 4. If the subdisk is part of a multi-plex volume, we'll change to
|
|
|
|
* reviving and let the revive routines find out whether it will work
|
|
|
|
* or not. If they don't, the revive stops with an error message,
|
1999-01-29 01:17:54 +00:00
|
|
|
* but the state doesn't change (FWIW).
|
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
if (sd->plexno < 0) /* no plex associated, */
|
|
|
|
break; /* bring it up */
|
|
|
|
plex = &PLEX[sd->plexno];
|
|
|
|
if (plex->volno >= 0) /* have a volume */
|
|
|
|
vol = &VOL[plex->volno];
|
|
|
|
else
|
|
|
|
vol = NULL;
|
1999-03-02 06:57:08 +00:00
|
|
|
/*
|
|
|
|
* We can't do it if:
|
|
|
|
*
|
|
|
|
* 1: we don't have a volume
|
|
|
|
* 2: we're the only plex in the volume
|
|
|
|
* 3: we're a RAID-5 plex, and more than one subdisk is down.
|
|
|
|
*/
|
|
|
|
if (((vol == NULL)
|
|
|
|
|| (vol->plexes == 1))
|
|
|
|
&& ((plex->organization != plex_raid5)
|
|
|
|
|| (plex->sddowncount > 1)))
|
1999-01-21 00:40:32 +00:00
|
|
|
return 0; /* can't do it */
|
|
|
|
sd->state = sd_reviving; /* put in reviving state */
|
|
|
|
sd->revived = 0; /* nothing done yet */
|
|
|
|
status = EAGAIN; /* need to repeat */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_reviving:
|
|
|
|
if (flags & setstate_force) /* insist, */
|
|
|
|
break;
|
|
|
|
return EAGAIN; /* no, try again */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
default: /* can't do it */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* There's no way to bring subdisks up directly from
|
1998-12-28 04:56:24 +00:00
|
|
|
* other states. First they need to be initialized
|
1999-03-28 08:54:48 +00:00
|
|
|
* or revived
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* other ones, only internal with force */
|
1999-01-27 20:09:21 +00:00
|
|
|
if ((flags & setstate_force) == 0) /* no force? What's this? */
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0; /* don't do it */
|
|
|
|
}
|
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
if (status == 1) { /* we can do it, */
|
|
|
|
sd->state = newstate;
|
1999-07-02 07:57:28 +00:00
|
|
|
if (flags & setstate_force)
|
|
|
|
log(LOG_INFO, "vinum: %s is %s by force\n", sd->name, sd_state(sd->state));
|
|
|
|
else
|
|
|
|
log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
|
1999-01-21 00:40:32 +00:00
|
|
|
} else /* we don't get here with status 0 */
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO,
|
|
|
|
"vinum: %s is %s, not %s\n",
|
|
|
|
sd->name,
|
|
|
|
sd_state(sd->state),
|
|
|
|
sd_state(newstate));
|
1999-01-21 00:40:32 +00:00
|
|
|
if (sd->plexno >= 0) /* we belong to a plex */
|
|
|
|
update_plex_state(sd->plexno); /* update plex state */
|
|
|
|
if ((flags & setstate_configuring) == 0) /* save config now */
|
|
|
|
save_config();
|
1998-12-28 04:56:24 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Set the state of a plex dependent on its subdisks.
|
1999-01-21 00:40:32 +00:00
|
|
|
* This time round, we'll let plex state just reflect
|
|
|
|
* aggregate subdisk state, so this becomes an order of
|
|
|
|
* magnitude less complicated. In particular, ignore
|
|
|
|
* the requested state.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
set_plex_state(int plexno, enum plexstate state, enum setstateflags flags)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:32 +00:00
|
|
|
struct plex *plex; /* point to our plex */
|
|
|
|
enum plexstate oldstate;
|
|
|
|
enum volplexstate vps; /* how do we compare with the other plexes? */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
plex = &PLEX[plexno]; /* point to our plex */
|
|
|
|
oldstate = plex->state;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
/* If the plex isn't allocated, we can't do it. */
|
|
|
|
if (plex->state == plex_unallocated)
|
|
|
|
return 0;
|
|
|
|
|
1999-03-02 06:57:08 +00:00
|
|
|
/*
|
1999-08-14 06:30:56 +00:00
|
|
|
* If it's already in the the state we want,
|
1999-03-02 06:57:08 +00:00
|
|
|
* and it's not up, just return. If it's up,
|
|
|
|
* we still need to do some housekeeping.
|
|
|
|
*/
|
1999-08-14 06:30:56 +00:00
|
|
|
if ((state == oldstate)
|
|
|
|
&& (state != plex_up))
|
|
|
|
return 1;
|
1999-01-21 00:40:32 +00:00
|
|
|
vps = vpstate(plex); /* how do we compare with the other plexes? */
|
|
|
|
switch (state) {
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* We can't bring the plex up, even by force,
|
1999-01-21 00:40:32 +00:00
|
|
|
* unless it's ready. update_plex_state
|
1999-03-28 08:54:48 +00:00
|
|
|
* checks that
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
case plex_up: /* bring the plex up */
|
|
|
|
update_plex_state(plex->plexno); /* it'll come up if it can */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_down: /* want to take it down */
|
1999-03-02 06:57:08 +00:00
|
|
|
/*
|
|
|
|
* If we're the only one, or the only one
|
|
|
|
* which is up, we need force to do it.
|
|
|
|
*/
|
|
|
|
if (((vps == volplex_onlyus)
|
|
|
|
|| (vps == volplex_onlyusup))
|
|
|
|
&& (!(flags & setstate_force)))
|
1999-01-21 00:40:32 +00:00
|
|
|
return 0; /* can't do it */
|
|
|
|
plex->state = state; /* do it */
|
|
|
|
invalidate_subdisks(plex, sd_down); /* and down all up subdisks */
|
|
|
|
break;
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* This is only requested internally.
|
1999-03-28 08:54:48 +00:00
|
|
|
* Trust ourselves
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
case plex_faulty:
|
|
|
|
plex->state = state; /* do it */
|
|
|
|
invalidate_subdisks(plex, sd_crashed); /* and crash all up subdisks */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_initializing:
|
|
|
|
/* XXX consider what safeguards we need here */
|
|
|
|
if ((flags & setstate_force) == 0)
|
|
|
|
return 0;
|
|
|
|
plex->state = state; /* do it */
|
|
|
|
break;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
/* What's this? */
|
1998-12-28 04:56:24 +00:00
|
|
|
default:
|
1999-01-21 00:40:32 +00:00
|
|
|
return 0;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
if (plex->state != oldstate) /* we've changed, */
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO, /* tell them about it */
|
|
|
|
"vinum: %s is %s\n",
|
|
|
|
plex->name,
|
|
|
|
plex_state(plex->state));
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Now see what we have left, and whether
|
1999-03-28 08:54:48 +00:00
|
|
|
* we're taking the volume down
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
if (plex->volno >= 0) /* we have a volume */
|
|
|
|
update_volume_state(plex->volno); /* update its state */
|
|
|
|
if ((flags & setstate_configuring) == 0) /* save config now */
|
|
|
|
save_config(); /* yes: save the updated configuration */
|
|
|
|
return 1;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
/* Update the state of a plex dependent on its plexes. */
|
|
|
|
int
|
|
|
|
set_volume_state(int volno, enum volumestate state, enum setstateflags flags)
|
|
|
|
{
|
|
|
|
struct volume *vol = &VOL[volno]; /* point to our volume */
|
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
if (vol->state == volume_unallocated) /* no volume to do anything with, */
|
1999-01-21 00:40:32 +00:00
|
|
|
return 0;
|
1999-08-14 06:30:56 +00:00
|
|
|
if (vol->state == state) /* we're there already */
|
|
|
|
return 1;
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
if (state == volume_up) /* want to come up */
|
|
|
|
update_volume_state(volno);
|
|
|
|
else if (state == volume_down) { /* want to go down */
|
1999-03-13 07:39:17 +00:00
|
|
|
if (((vol->flags & VF_OPEN) == 0) /* not open */
|
1999-01-21 00:40:32 +00:00
|
|
|
||((flags & setstate_force) != 0)) { /* or we're forcing */
|
|
|
|
vol->state = volume_down;
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO,
|
|
|
|
"vinum: volume %s is %s\n",
|
|
|
|
vol->name,
|
|
|
|
volume_state(vol->state));
|
1999-01-21 00:40:32 +00:00
|
|
|
if ((flags & setstate_configuring) == 0) /* save config now */
|
|
|
|
save_config(); /* yes: save the updated configuration */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; /* no change */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the state of a subdisk based on its environment */
|
1998-12-28 04:56:24 +00:00
|
|
|
void
|
1999-01-21 00:40:32 +00:00
|
|
|
update_sd_state(int sdno)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:32 +00:00
|
|
|
struct sd *sd;
|
|
|
|
struct drive *drive;
|
|
|
|
enum sdstate oldstate;
|
|
|
|
|
|
|
|
sd = &SD[sdno];
|
|
|
|
oldstate = sd->state;
|
|
|
|
drive = &DRIVE[sd->driveno];
|
|
|
|
|
|
|
|
if (drive->state == drive_up) {
|
|
|
|
switch (sd->state) {
|
|
|
|
case sd_down:
|
|
|
|
case sd_crashed:
|
|
|
|
sd->state = sd_reborn; /* back up again with no loss */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else { /* down or worse */
|
|
|
|
switch (sd->state) {
|
|
|
|
case sd_up:
|
|
|
|
case sd_reborn:
|
|
|
|
case sd_reviving:
|
1999-04-10 08:12:12 +00:00
|
|
|
case sd_empty:
|
1999-01-21 00:40:32 +00:00
|
|
|
sd->state = sd_crashed; /* lost our drive */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sd->state != oldstate) /* state has changed, */
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO, /* say so */
|
|
|
|
"vinum: %s is %s\n",
|
|
|
|
sd->name,
|
|
|
|
sd_state(sd->state));
|
1999-01-21 00:40:32 +00:00
|
|
|
if (sd->plexno >= 0) /* we're part of a plex, */
|
|
|
|
update_plex_state(sd->plexno); /* update its state */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-03-28 08:54:48 +00:00
|
|
|
/*
|
|
|
|
* Force a plex and all its subdisks
|
|
|
|
* into an 'up' state. This is a helper
|
|
|
|
* for update_plex_state.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
forceup(int plexno)
|
|
|
|
{
|
|
|
|
struct plex *plex;
|
|
|
|
int sdno;
|
|
|
|
|
|
|
|
plex = &PLEX[plexno]; /* point to the plex */
|
|
|
|
plex->state = plex_up; /* and bring it up */
|
|
|
|
|
|
|
|
/* change the subdisks to up state */
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) {
|
|
|
|
SD[plex->sdnos[sdno]].state = sd_up;
|
|
|
|
log(LOG_INFO, /* tell them about it */
|
|
|
|
"vinum: %s is up\n",
|
|
|
|
SD[plex->sdnos[sdno]].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
/* Set the state of a plex based on its environment */
|
1998-12-28 04:56:24 +00:00
|
|
|
void
|
1999-01-21 00:40:32 +00:00
|
|
|
update_plex_state(int plexno)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:32 +00:00
|
|
|
struct plex *plex; /* point to our plex */
|
|
|
|
enum plexstate oldstate;
|
|
|
|
enum sdstates statemap; /* get a map of the subdisk states */
|
1999-03-28 08:54:48 +00:00
|
|
|
enum volplexstate vps; /* how do we compare with the other plexes? */
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
plex = &PLEX[plexno]; /* point to our plex */
|
|
|
|
oldstate = plex->state;
|
|
|
|
statemap = sdstatemap(plex); /* get a map of the subdisk states */
|
1999-03-28 08:54:48 +00:00
|
|
|
vps = vpstate(plex); /* how do we compare with the other plexes? */
|
|
|
|
|
1999-08-14 06:30:56 +00:00
|
|
|
if (statemap & sd_initstate) /* something initializing? */
|
1999-08-07 08:14:01 +00:00
|
|
|
plex->state = plex_initializing; /* yup, that makes the plex the same */
|
1999-03-28 08:54:48 +00:00
|
|
|
if ((statemap == sd_emptystate) /* all subdisks empty */
|
|
|
|
&&((vps & volplex_otherup) == 0) /* and no other plex is up */ &&((plex->organization == plex_concat) /* and we're not RAID-5 */
|
|
|
|
||(plex->organization == plex_striped))) {
|
|
|
|
struct volume *vol = &VOL[plex->volno]; /* possible volume to which it points */
|
1999-01-21 00:40:32 +00:00
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
1999-03-28 08:54:48 +00:00
|
|
|
* If we're a striped or concat plex associated with a
|
|
|
|
* volume, none of whose plexes are up, and we're new and
|
|
|
|
* untested, and the volume has the setupstate bit set, we
|
|
|
|
* can pretend to be in a consistent state.
|
|
|
|
*
|
|
|
|
* We need to do this in one swell foop: on the next call
|
|
|
|
* we will no longer be just empty.
|
|
|
|
*
|
|
|
|
* This code assumes that all the other plexes are also
|
|
|
|
* capable of coming up (i.e. all the sds are up), but
|
|
|
|
* that's OK: we'll come back to this function for the
|
|
|
|
* remaining plexes in the volume.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-03-28 08:54:48 +00:00
|
|
|
|
|
|
|
if ((plex->state == plex_init)
|
|
|
|
&& (plex->volno >= 0)
|
|
|
|
&& (vol->flags & VF_CONFIG_SETUPSTATE)) {
|
|
|
|
for (plexno = 0; plexno < vol->plexes; plexno++)
|
|
|
|
forceup(VOL[plex->volno].plex[plexno]);
|
|
|
|
} else
|
|
|
|
forceup(plexno); /* we'll do it */
|
|
|
|
} else if (statemap == sd_upstate)
|
|
|
|
/*
|
|
|
|
* All the subdisks are up. This also means that
|
|
|
|
* they are consistent, so we can just bring
|
|
|
|
* the plex up
|
|
|
|
*/
|
|
|
|
plex->state = plex_up;
|
1999-08-07 08:14:01 +00:00
|
|
|
else if ((plex->organization == plex_raid5) /* raid 5 plex */
|
|
|
|
&&(plex->sddowncount == 1)) /* and exactly one subdisk down */
|
|
|
|
plex->state = plex_degraded; /* limping a bit */
|
1999-03-28 08:54:48 +00:00
|
|
|
else if ((statemap & (sd_upstate | sd_rebornstate)) == statemap) /* all up or reborn */
|
1999-01-21 00:40:32 +00:00
|
|
|
plex->state = plex_flaky;
|
|
|
|
else if (statemap & (sd_upstate | sd_rebornstate)) /* some up or reborn */
|
|
|
|
plex->state = plex_corrupt; /* corrupt */
|
1999-03-28 08:54:48 +00:00
|
|
|
else if (statemap & (sd_initstate | sd_emptystate)) /* some subdisks empty or initializing */
|
1999-01-21 00:40:32 +00:00
|
|
|
plex->state = plex_initializing;
|
|
|
|
else /* nothing at all up */
|
|
|
|
plex->state = plex_faulty;
|
|
|
|
|
|
|
|
if (plex->state != oldstate) /* state has changed, */
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO, /* tell them about it */
|
|
|
|
"vinum: %s is %s\n",
|
|
|
|
plex->name,
|
|
|
|
plex_state(plex->state));
|
1999-01-21 00:40:32 +00:00
|
|
|
if (plex->volno >= 0) /* we're part of a volume, */
|
|
|
|
update_volume_state(plex->volno); /* update its state */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
/* Set volume state based on its components */
|
1998-12-28 04:56:24 +00:00
|
|
|
void
|
1999-01-21 00:40:32 +00:00
|
|
|
update_volume_state(int volno)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:32 +00:00
|
|
|
struct volume *vol; /* our volume */
|
|
|
|
int plexno;
|
|
|
|
enum volumestate oldstate;
|
|
|
|
|
|
|
|
vol = &VOL[volno]; /* point to our volume */
|
|
|
|
oldstate = vol->state;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
for (plexno = 0; plexno < vol->plexes; plexno++) {
|
|
|
|
struct plex *plex = &PLEX[vol->plex[plexno]]; /* point to the plex */
|
|
|
|
if (plex->state >= plex_corrupt) { /* something accessible, */
|
|
|
|
vol->state = volume_up;
|
|
|
|
break;
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
if (plexno == vol->plexes) /* didn't find an up plex */
|
|
|
|
vol->state = volume_down;
|
|
|
|
|
|
|
|
if (vol->state != oldstate) { /* state changed */
|
1999-03-02 06:57:08 +00:00
|
|
|
log(LOG_INFO, "vinum: %s is %s\n", vol->name, volume_state(vol->state));
|
1999-01-21 00:40:32 +00:00
|
|
|
save_config(); /* save the updated configuration */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
}
|
|
|
|
|
1999-08-07 08:14:01 +00:00
|
|
|
/*
|
|
|
|
* Helper for checksdstate. If this is a write
|
|
|
|
* operation, it's no necessarily the end of the
|
|
|
|
* world that we can't write: there could be
|
|
|
|
* another plex which can satisfy the operation.
|
|
|
|
* We must write everything we can, though, so we
|
|
|
|
* don't want to stop when we hit a subdisk which
|
|
|
|
* is down. Return a separate indication instead.
|
|
|
|
*/
|
|
|
|
enum requeststatus
|
|
|
|
sddownstate(struct request *rq)
|
|
|
|
{
|
|
|
|
if (rq->bp->b_flags & B_READ) /* read operation? */
|
|
|
|
return REQUEST_DOWN; /* OK, can't do it */
|
|
|
|
else
|
|
|
|
return REQUEST_DEGRADED;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Called from request routines when they find
|
1999-01-21 00:40:32 +00:00
|
|
|
* a subdisk which is not kosher. Decide whether
|
|
|
|
* it warrants changing the state. Return
|
|
|
|
* REQUEST_DOWN if we can't use the subdisk,
|
1999-03-28 08:54:48 +00:00
|
|
|
* REQUEST_OK if we can.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* A prior version of this function checked the plex
|
1999-01-21 00:40:32 +00:00
|
|
|
* state as well. At the moment, consider plex states
|
|
|
|
* information for the user only. We'll ignore them
|
|
|
|
* and use the subdisk state only. The last version of
|
1999-03-28 08:54:48 +00:00
|
|
|
* this file with the old logic was 2.7. XXX
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
enum requeststatus
|
|
|
|
checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend)
|
|
|
|
{
|
|
|
|
struct plex *plex = &PLEX[sd->plexno];
|
|
|
|
int writeop = (rq->bp->b_flags & B_READ) == 0; /* note if we're writing */
|
|
|
|
|
|
|
|
switch (sd->state) {
|
|
|
|
/* We shouldn't get called if the subdisk is up */
|
|
|
|
case sd_up:
|
|
|
|
return REQUEST_OK;
|
|
|
|
|
|
|
|
case sd_reviving:
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Access to a reviving subdisk depends on the
|
1999-01-21 00:40:32 +00:00
|
|
|
* organization of the plex:
|
|
|
|
|
|
|
|
* - If it's concatenated, access the subdisk up to its current
|
|
|
|
* revive point. If we want to write to the subdisk overlapping the
|
|
|
|
* current revive block, set the conflict flag in the request, asking
|
|
|
|
* the caller to put the request on the wait list, which will be
|
|
|
|
* attended to by revive_block when it's done.
|
|
|
|
* - if it's striped, we can't do it (we could do some hairy
|
|
|
|
* calculations, but it's unlikely to work).
|
|
|
|
* - if it's RAID-5, we can do it as long as only one
|
1999-03-28 08:54:48 +00:00
|
|
|
* subdisk is down
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:32 +00:00
|
|
|
if (plex->state == plex_striped) /* plex is striped, */
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
|
|
|
|
|
|
|
else if (plex->state == plex_raid5) { /* RAID5 plex */
|
|
|
|
if (plex->sddowncount > 1) /* with more than one sd down, */
|
|
|
|
return sddownstate(rq);
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* XXX We shouldn't do this if we can find a
|
|
|
|
* better way. Check the other plexes
|
|
|
|
* first, and return a DOWN if another
|
|
|
|
* plex will do it better
|
|
|
|
*/
|
|
|
|
return REQUEST_OK; /* OK, we'll find a way */
|
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
if (diskaddr > (sd->revived
|
|
|
|
+ sd->plexoffset
|
|
|
|
+ (sd->revive_blocksize >> DEV_BSHIFT))) /* we're beyond the end */
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1999-01-21 00:40:32 +00:00
|
|
|
else if (diskend > (sd->revived + sd->plexoffset)) { /* we finish beyond the end */
|
|
|
|
if (writeop) {
|
|
|
|
rq->flags |= XFR_REVIVECONFLICT; /* note a potential conflict */
|
|
|
|
rq->sdno = sd->sdno; /* and which sd last caused it */
|
|
|
|
} else
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1999-01-21 00:40:32 +00:00
|
|
|
}
|
|
|
|
return REQUEST_OK;
|
|
|
|
|
|
|
|
case sd_reborn:
|
|
|
|
if (writeop)
|
|
|
|
return REQUEST_OK; /* always write to a reborn disk */
|
|
|
|
else /* don't allow a read */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Handle the mapping. We don't want to reject
|
1999-01-21 00:40:32 +00:00
|
|
|
* a read request to a reborn subdisk if that's
|
1999-03-28 08:54:48 +00:00
|
|
|
* all we have. XXX
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
case sd_down:
|
|
|
|
if (writeop) /* writing to a consistent down disk */
|
|
|
|
set_sd_state(sd->sdno, sd_obsolete, setstate_force); /* it's not consistent now */
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
case sd_crashed:
|
|
|
|
if (writeop) /* writing to a consistent down disk */
|
|
|
|
set_sd_state(sd->sdno, sd_stale, setstate_force); /* it's not consistent now */
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
default:
|
1999-08-07 08:14:01 +00:00
|
|
|
return sddownstate(rq);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return a state map for the subdisks of a plex */
|
|
|
|
enum sdstates
|
1999-01-21 00:40:32 +00:00
|
|
|
sdstatemap(struct plex *plex)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
int sdno;
|
|
|
|
enum sdstates statemap = 0; /* note the states we find */
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
plex->sddowncount = 0; /* no subdisks down yet */
|
1998-12-28 04:56:24 +00:00
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) {
|
|
|
|
struct sd *sd = &SD[plex->sdnos[sdno]]; /* point to the subdisk */
|
|
|
|
|
|
|
|
switch (sd->state) {
|
|
|
|
case sd_empty:
|
|
|
|
statemap |= sd_emptystate;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_init:
|
|
|
|
statemap |= sd_initstate;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_down:
|
|
|
|
statemap |= sd_downstate;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_crashed:
|
|
|
|
statemap |= sd_crashedstate;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_obsolete:
|
|
|
|
statemap |= sd_obsolete;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_stale:
|
|
|
|
statemap |= sd_stalestate;
|
1999-01-21 00:40:32 +00:00
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_reborn:
|
|
|
|
statemap |= sd_rebornstate;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_up:
|
|
|
|
statemap |= sd_upstate;
|
|
|
|
break;
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
case sd_initializing:
|
|
|
|
statemap |= sd_initstate;
|
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
1999-01-21 00:40:32 +00:00
|
|
|
|
|
|
|
case sd_unallocated:
|
|
|
|
case sd_uninit:
|
|
|
|
case sd_reviving:
|
1999-03-28 08:54:48 +00:00
|
|
|
case sd_referenced:
|
1999-01-21 00:40:32 +00:00
|
|
|
statemap |= sd_otherstate;
|
|
|
|
(plex->sddowncount)++; /* another unusable subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return statemap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine the state of the volume relative to this plex */
|
|
|
|
enum volplexstate
|
|
|
|
vpstate(struct plex *plex)
|
|
|
|
{
|
|
|
|
struct volume *vol;
|
|
|
|
enum volplexstate state = volplex_onlyusdown; /* state to return */
|
|
|
|
int plexno;
|
|
|
|
|
|
|
|
if (plex->volno < 0) /* not associated with a volume */
|
|
|
|
return volplex_onlyusdown; /* assume the worst */
|
|
|
|
|
|
|
|
vol = &VOL[plex->volno]; /* point to our volume */
|
|
|
|
for (plexno = 0; plexno < vol->plexes; plexno++) {
|
|
|
|
if (&PLEX[vol->plex[plexno]] == plex) { /* us */
|
1999-08-07 08:14:01 +00:00
|
|
|
if (PLEX[vol->plex[plexno]].state >= plex_degraded) /* are we up? */
|
1998-12-28 04:56:24 +00:00
|
|
|
state |= volplex_onlyus; /* yes */
|
|
|
|
} else {
|
1999-08-07 08:14:01 +00:00
|
|
|
if (PLEX[vol->plex[plexno]].state >= plex_degraded) /* not us */
|
1998-12-28 04:56:24 +00:00
|
|
|
state |= volplex_otherup; /* and when they were up, they were up */
|
|
|
|
else
|
|
|
|
state |= volplex_alldown; /* and when they were down, they were down */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state; /* and when they were only halfway up */
|
|
|
|
} /* they were neither up nor down */
|
|
|
|
|
|
|
|
/* Check if all bits b are set in a */
|
|
|
|
int allset(int a, int b);
|
|
|
|
|
|
|
|
int
|
|
|
|
allset(int a, int b)
|
|
|
|
{
|
|
|
|
return (a & b) == b;
|
|
|
|
}
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
/* Invalidate the subdisks belonging to a plex */
|
|
|
|
void
|
|
|
|
invalidate_subdisks(struct plex *plex, enum sdstate state)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:32 +00:00
|
|
|
int sdno;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) { /* for each subdisk */
|
|
|
|
struct sd *sd = &SD[plex->sdnos[sdno]];
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
switch (sd->state) {
|
|
|
|
case sd_unallocated:
|
|
|
|
case sd_uninit:
|
|
|
|
case sd_init:
|
|
|
|
case sd_initializing:
|
|
|
|
case sd_empty:
|
|
|
|
case sd_obsolete:
|
|
|
|
case sd_stale:
|
|
|
|
case sd_crashed:
|
|
|
|
case sd_down:
|
1999-03-28 08:54:48 +00:00
|
|
|
case sd_referenced:
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
1999-01-21 00:40:32 +00:00
|
|
|
case sd_reviving:
|
|
|
|
case sd_reborn:
|
|
|
|
case sd_up:
|
|
|
|
set_sd_state(plex->sdnos[sdno], state, setstate_force);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Start an object, in other words do what we can to get it up.
|
1998-12-28 04:56:24 +00:00
|
|
|
* This is called from vinumioctl (VINUMSTART).
|
|
|
|
* Return error indications via ioctl_reply
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
start_object(struct vinum_ioctl_msg *data)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int objindex = data->index; /* data gets overwritten */
|
|
|
|
struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */
|
1999-01-21 00:40:32 +00:00
|
|
|
enum setstateflags flags;
|
|
|
|
|
|
|
|
if (data->force != 0) /* are we going to use force? */
|
|
|
|
flags = setstate_force; /* yes */
|
|
|
|
else
|
|
|
|
flags = setstate_none; /* no */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
switch (data->type) {
|
|
|
|
case drive_object:
|
1999-01-21 00:40:32 +00:00
|
|
|
status = set_drive_state(objindex, drive_up, flags);
|
|
|
|
if (DRIVE[objindex].state != drive_up) /* set status on whether we really did it */
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1999-01-21 00:40:32 +00:00
|
|
|
else
|
|
|
|
ioctl_reply->error = 0;
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_object:
|
1999-01-21 00:40:32 +00:00
|
|
|
if (SD[objindex].state == sd_reviving) { /* reviving, */
|
1998-12-28 04:56:24 +00:00
|
|
|
ioctl_reply->error = revive_block(objindex); /* revive another block */
|
|
|
|
ioctl_reply->msg[0] = '\0'; /* no comment */
|
|
|
|
return;
|
|
|
|
}
|
1999-01-21 00:40:32 +00:00
|
|
|
status = set_sd_state(objindex, sd_up, flags); /* set state */
|
|
|
|
if (status == EAGAIN) { /* first revive, */
|
|
|
|
ioctl_reply->error = revive_block(objindex); /* revive the first block */
|
|
|
|
ioctl_reply->error = EAGAIN;
|
|
|
|
} else {
|
|
|
|
if (SD[objindex].state != sd_up) /* set status on whether we really did it */
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1999-01-21 00:40:32 +00:00
|
|
|
else
|
|
|
|
ioctl_reply->error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_object:
|
|
|
|
status = set_plex_state(objindex, plex_up, flags);
|
|
|
|
if (PLEX[objindex].state != plex_up) /* set status on whether we really did it */
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1999-01-21 00:40:32 +00:00
|
|
|
else
|
|
|
|
ioctl_reply->error = 0;
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case volume_object:
|
1999-01-21 00:40:32 +00:00
|
|
|
status = set_volume_state(objindex, volume_up, flags);
|
|
|
|
if (VOL[objindex].state != volume_up) /* set status on whether we really did it */
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1999-01-21 00:40:32 +00:00
|
|
|
else
|
|
|
|
ioctl_reply->error = 0;
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ioctl_reply->error = EINVAL;
|
|
|
|
strcpy(ioctl_reply->msg, "Invalid object type");
|
|
|
|
return;
|
|
|
|
}
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* There's no point in saying anything here:
|
1999-03-28 08:54:48 +00:00
|
|
|
* the userland program does it better
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
ioctl_reply->msg[0] = '\0';
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Stop an object, in other words do what we can to get it down
|
1998-12-28 04:56:24 +00:00
|
|
|
* This is called from vinumioctl (VINUMSTOP).
|
|
|
|
* Return error indications via ioctl_reply.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
stop_object(struct vinum_ioctl_msg *data)
|
|
|
|
{
|
|
|
|
int status = 1;
|
|
|
|
int objindex = data->index; /* save the number from change */
|
|
|
|
struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */
|
|
|
|
|
|
|
|
switch (data->type) {
|
|
|
|
case drive_object:
|
|
|
|
status = set_drive_state(objindex, drive_down, data->force);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sd_object:
|
|
|
|
status = set_sd_state(objindex, sd_down, data->force);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_object:
|
|
|
|
status = set_plex_state(objindex, plex_down, data->force);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case volume_object:
|
|
|
|
status = set_volume_state(objindex, volume_down, data->force);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ioctl_reply->error = EINVAL;
|
|
|
|
strcpy(ioctl_reply->msg, "Invalid object type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ioctl_reply->msg[0] = '\0';
|
|
|
|
if (status == 0) /* couldn't do it */
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1998-12-28 04:56:24 +00:00
|
|
|
else
|
|
|
|
ioctl_reply->error = 0;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* VINUM_SETSTATE ioctl: set an object state
|
1999-03-28 08:54:48 +00:00
|
|
|
* msg is the message passed by the user
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
void
|
|
|
|
setstate(struct vinum_ioctl_msg *msg)
|
|
|
|
{
|
|
|
|
int sdno;
|
|
|
|
struct sd *sd;
|
|
|
|
struct plex *plex;
|
|
|
|
struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) msg; /* format for returning replies */
|
|
|
|
|
|
|
|
switch (msg->state) {
|
|
|
|
case object_down:
|
|
|
|
stop_object(msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case object_initializing:
|
|
|
|
switch (msg->type) {
|
|
|
|
case sd_object:
|
|
|
|
sd = &SD[msg->index];
|
1999-03-30 04:59:32 +00:00
|
|
|
if ((msg->index >= vinum_conf.subdisks_allocated)
|
|
|
|
|| (sd->state <= sd_referenced)) {
|
1998-12-28 04:56:24 +00:00
|
|
|
sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index);
|
|
|
|
ioctl_reply->error = EFAULT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_sd_state(msg->index, sd_initializing, msg->force);
|
|
|
|
if (sd->state != sd_initializing) {
|
|
|
|
strcpy(ioctl_reply->msg, "Can't set state");
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1998-12-28 04:56:24 +00:00
|
|
|
} else
|
|
|
|
ioctl_reply->error = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_object:
|
|
|
|
plex = &PLEX[msg->index];
|
1999-03-30 04:59:32 +00:00
|
|
|
if ((msg->index >= vinum_conf.plexes_allocated)
|
|
|
|
|| (plex->state <= plex_unallocated)) {
|
1999-03-24 00:43:05 +00:00
|
|
|
sprintf(ioctl_reply->msg, "Invalid plex %d", msg->index);
|
1998-12-28 04:56:24 +00:00
|
|
|
ioctl_reply->error = EFAULT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_plex_state(msg->index, plex_initializing, msg->force);
|
|
|
|
if (plex->state != plex_initializing) {
|
|
|
|
strcpy(ioctl_reply->msg, "Can't set state");
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1998-12-28 04:56:24 +00:00
|
|
|
} else {
|
|
|
|
ioctl_reply->error = 0;
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) {
|
|
|
|
sd = &SD[plex->sdnos[sdno]];
|
|
|
|
set_sd_state(plex->sdnos[sdno], sd_initializing, msg->force);
|
|
|
|
if (sd->state != sd_initializing) {
|
|
|
|
strcpy(ioctl_reply->msg, "Can't set state");
|
1999-07-02 07:57:28 +00:00
|
|
|
ioctl_reply->error = EBUSY;
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
strcpy(ioctl_reply->msg, "Invalid object");
|
|
|
|
ioctl_reply->error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case object_up:
|
|
|
|
start_object(msg);
|
|
|
|
}
|
|
|
|
}
|