2003-06-23 15:53:35 +04:00
|
|
|
/* $NetBSD: raidctl.c,v 1.33 2003/06/23 11:53:40 agc Exp $ */
|
2000-05-23 04:46:53 +04:00
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Greg Oster
|
|
|
|
*
|
|
|
|
* 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 the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-05-23 04:46:53 +04:00
|
|
|
* This program is a re-write of the original rf_ctrl program
|
|
|
|
* distributed by CMU with RAIDframe 1.1.
|
|
|
|
*
|
|
|
|
* This program is the user-land interface to the RAIDframe kernel
|
|
|
|
* driver in NetBSD.
|
1998-11-13 07:34:02 +03:00
|
|
|
*/
|
2003-06-23 15:53:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
__RCSID("$NetBSD: raidctl.c,v 1.33 2003/06/23 11:53:40 agc Exp $");
|
|
|
|
#endif
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
2000-05-23 04:46:53 +04:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
1999-01-13 01:58:10 +03:00
|
|
|
#include <errno.h>
|
2000-10-31 17:18:39 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
1999-02-24 03:03:12 +03:00
|
|
|
#include <stdlib.h>
|
2000-10-31 17:18:39 +03:00
|
|
|
#include <string.h>
|
1999-01-26 05:40:02 +03:00
|
|
|
#include <unistd.h>
|
2000-10-31 17:18:39 +03:00
|
|
|
#include <util.h>
|
1999-01-26 05:40:02 +03:00
|
|
|
|
2001-10-04 20:02:08 +04:00
|
|
|
#include <dev/raidframe/raidframevar.h>
|
|
|
|
#include <dev/raidframe/raidframeio.h>
|
|
|
|
#include "rf_configure.h"
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
int main __P((int, char *[]));
|
2000-05-23 04:46:53 +04:00
|
|
|
void do_ioctl __P((int, u_long, void *, const char *));
|
1999-02-24 03:03:12 +03:00
|
|
|
static void rf_configure __P((int, char*, int));
|
2000-05-23 04:46:53 +04:00
|
|
|
static const char *device_status __P((RF_DiskStatus_t));
|
1998-11-13 07:34:02 +03:00
|
|
|
static void rf_get_device_status __P((int));
|
2001-07-10 05:30:52 +04:00
|
|
|
static void rf_output_configuration __P((int, const char *));
|
1999-03-02 06:13:59 +03:00
|
|
|
static void get_component_number __P((int, char *, int *, int *));
|
1998-11-13 07:34:02 +03:00
|
|
|
static void rf_fail_disk __P((int, char *, int));
|
|
|
|
static void usage __P((void));
|
1999-02-24 03:03:12 +03:00
|
|
|
static void get_component_label __P((int, char *));
|
|
|
|
static void set_component_label __P((int, char *));
|
|
|
|
static void init_component_labels __P((int, int));
|
2000-02-13 07:55:30 +03:00
|
|
|
static void set_autoconfig __P((int, int, char *));
|
1999-02-24 03:03:12 +03:00
|
|
|
static void add_hot_spare __P((int, char *));
|
1999-03-02 06:13:59 +03:00
|
|
|
static void remove_hot_spare __P((int, char *));
|
|
|
|
static void rebuild_in_place __P((int, char *));
|
2000-02-26 01:24:11 +03:00
|
|
|
static void check_status __P((int,int));
|
2000-05-23 04:46:53 +04:00
|
|
|
static void check_parity __P((int,int, char *));
|
2000-05-23 04:33:13 +04:00
|
|
|
static void do_meter __P((int, u_long));
|
2000-01-05 06:02:41 +03:00
|
|
|
static void get_bar __P((char *, double, int));
|
|
|
|
static void get_time_string __P((char *, int));
|
|
|
|
|
2000-05-23 04:46:53 +04:00
|
|
|
int verbose;
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
main(argc,argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
int num_options;
|
|
|
|
unsigned long action;
|
|
|
|
char config_filename[PATH_MAX];
|
|
|
|
char dev_name[PATH_MAX];
|
|
|
|
char name[PATH_MAX];
|
1999-02-24 03:03:12 +03:00
|
|
|
char component[PATH_MAX];
|
2000-02-13 07:55:30 +03:00
|
|
|
char autoconf[10];
|
2001-07-10 05:30:52 +04:00
|
|
|
int do_output;
|
1998-11-13 07:34:02 +03:00
|
|
|
int do_recon;
|
1999-08-10 22:21:39 +04:00
|
|
|
int do_rewrite;
|
|
|
|
int is_clean;
|
1998-11-13 07:34:02 +03:00
|
|
|
int raidID;
|
1999-02-24 03:03:12 +03:00
|
|
|
int serial_number;
|
1998-11-13 07:34:02 +03:00
|
|
|
struct stat st;
|
|
|
|
int fd;
|
1999-02-24 03:03:12 +03:00
|
|
|
int force;
|
2002-03-21 03:27:11 +03:00
|
|
|
int openmode;
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
num_options = 0;
|
|
|
|
action = 0;
|
2001-07-10 05:30:52 +04:00
|
|
|
do_output = 0;
|
1998-11-13 07:34:02 +03:00
|
|
|
do_recon = 0;
|
1999-08-10 22:21:39 +04:00
|
|
|
do_rewrite = 0;
|
|
|
|
is_clean = 0;
|
1999-02-24 03:03:12 +03:00
|
|
|
force = 0;
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDWR; /* default to read/write */
|
1998-11-13 07:34:02 +03:00
|
|
|
|
2001-07-10 05:30:52 +04:00
|
|
|
while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:GiI:l:r:R:sSpPuv"))
|
2000-02-13 07:55:30 +03:00
|
|
|
!= -1)
|
1998-11-13 07:34:02 +03:00
|
|
|
switch(ch) {
|
1999-02-24 03:03:12 +03:00
|
|
|
case 'a':
|
|
|
|
action = RAIDFRAME_ADD_HOT_SPARE;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1999-02-24 03:03:12 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
2000-02-13 07:55:30 +03:00
|
|
|
case 'A':
|
|
|
|
action = RAIDFRAME_SET_AUTOCONFIG;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(autoconf, optarg, sizeof(autoconf));
|
2000-02-13 07:55:30 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case 'B':
|
|
|
|
action = RAIDFRAME_COPYBACK;
|
|
|
|
num_options++;
|
|
|
|
break;
|
1998-11-13 07:34:02 +03:00
|
|
|
case 'c':
|
|
|
|
action = RAIDFRAME_CONFIGURE;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(config_filename, optarg,
|
|
|
|
sizeof(config_filename));
|
1999-03-02 06:13:59 +03:00
|
|
|
force = 0;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'C':
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(config_filename, optarg,
|
|
|
|
sizeof(config_filename));
|
1999-03-02 06:13:59 +03:00
|
|
|
action = RAIDFRAME_CONFIGURE;
|
|
|
|
force = 1;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
action = RAIDFRAME_FAIL_DISK;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1999-03-02 06:13:59 +03:00
|
|
|
do_recon = 0;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
action = RAIDFRAME_FAIL_DISK;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1999-03-02 06:13:59 +03:00
|
|
|
do_recon = 1;
|
1999-02-24 03:03:12 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
action = RAIDFRAME_GET_COMPONENT_LABEL;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDONLY;
|
1999-02-24 03:03:12 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
2001-07-10 05:30:52 +04:00
|
|
|
case 'G':
|
|
|
|
action = RAIDFRAME_GET_INFO;
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDONLY;
|
2001-07-10 05:30:52 +04:00
|
|
|
do_output = 1;
|
|
|
|
num_options++;
|
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case 'i':
|
|
|
|
action = RAIDFRAME_REWRITEPARITY;
|
|
|
|
num_options++;
|
|
|
|
break;
|
1999-02-24 03:03:12 +03:00
|
|
|
case 'I':
|
|
|
|
action = RAIDFRAME_INIT_LABELS;
|
|
|
|
serial_number = atoi(optarg);
|
|
|
|
num_options++;
|
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case 'l':
|
1999-02-24 03:03:12 +03:00
|
|
|
action = RAIDFRAME_SET_COMPONENT_LABEL;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'r':
|
1999-03-02 06:13:59 +03:00
|
|
|
action = RAIDFRAME_REMOVE_HOT_SPARE;
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'R':
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(component, optarg, sizeof(component));
|
1999-03-02 06:13:59 +03:00
|
|
|
action = RAIDFRAME_REBUILD_IN_PLACE;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
action = RAIDFRAME_GET_INFO;
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDONLY;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case 'S':
|
2000-05-28 04:49:35 +04:00
|
|
|
action = RAIDFRAME_CHECK_RECON_STATUS_EXT;
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDONLY;
|
1998-11-13 07:34:02 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
1999-08-10 22:21:39 +04:00
|
|
|
case 'p':
|
|
|
|
action = RAIDFRAME_CHECK_PARITY;
|
2002-03-21 03:27:11 +03:00
|
|
|
openmode = O_RDONLY;
|
1999-08-10 22:21:39 +04:00
|
|
|
num_options++;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
action = RAIDFRAME_CHECK_PARITY;
|
|
|
|
do_rewrite = 1;
|
|
|
|
num_options++;
|
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case 'u':
|
|
|
|
action = RAIDFRAME_SHUTDOWN;
|
1999-02-24 03:03:12 +03:00
|
|
|
num_options++;
|
|
|
|
break;
|
2000-01-05 06:02:41 +03:00
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
/* Don't bump num_options, as '-v' is not
|
|
|
|
an option like the others */
|
|
|
|
/* num_options++; */
|
|
|
|
break;
|
1998-11-13 07:34:02 +03:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if ((num_options > 1) || (argc == NULL))
|
|
|
|
usage();
|
|
|
|
|
2003-04-15 11:36:14 +04:00
|
|
|
strlcpy(name, argv[0], sizeof(name));
|
2002-03-21 03:27:11 +03:00
|
|
|
fd = opendisk(name, openmode, dev_name, sizeof(dev_name), 1);
|
2000-10-31 17:18:39 +03:00
|
|
|
if (fd == -1) {
|
|
|
|
fprintf(stderr, "%s: unable to open device file: %s\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname(), name);
|
2000-10-31 17:18:39 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (fstat(fd, &st) != 0) {
|
1998-11-13 07:34:02 +03:00
|
|
|
fprintf(stderr,"%s: stat failure on: %s\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname(), dev_name);
|
2000-10-31 17:18:39 +03:00
|
|
|
exit(1);
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
|
|
|
|
fprintf(stderr,"%s: invalid device: %s\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname(), dev_name);
|
2000-10-31 17:18:39 +03:00
|
|
|
exit(1);
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
|
2001-09-26 06:59:40 +04:00
|
|
|
raidID = DISKUNIT(st.st_rdev);
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
switch(action) {
|
1999-02-24 03:03:12 +03:00
|
|
|
case RAIDFRAME_ADD_HOT_SPARE:
|
2000-02-13 07:55:30 +03:00
|
|
|
add_hot_spare(fd, component);
|
1999-02-24 03:03:12 +03:00
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case RAIDFRAME_REMOVE_HOT_SPARE:
|
2000-02-13 07:55:30 +03:00
|
|
|
remove_hot_spare(fd, component);
|
1999-03-02 06:13:59 +03:00
|
|
|
break;
|
1998-11-13 07:34:02 +03:00
|
|
|
case RAIDFRAME_CONFIGURE:
|
2000-02-13 07:55:30 +03:00
|
|
|
rf_configure(fd, config_filename, force);
|
|
|
|
break;
|
|
|
|
case RAIDFRAME_SET_AUTOCONFIG:
|
|
|
|
set_autoconfig(fd, raidID, autoconf);
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_COPYBACK:
|
|
|
|
printf("Copyback.\n");
|
|
|
|
do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
|
2000-01-05 06:02:41 +03:00
|
|
|
if (verbose) {
|
|
|
|
sleep(3); /* XXX give the copyback a chance to start */
|
|
|
|
printf("Copyback status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_FAIL_DISK:
|
2000-02-13 07:55:30 +03:00
|
|
|
rf_fail_disk(fd, component, do_recon);
|
1999-02-24 03:03:12 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_SET_COMPONENT_LABEL:
|
2000-02-13 07:55:30 +03:00
|
|
|
set_component_label(fd, component);
|
1999-02-24 03:03:12 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_GET_COMPONENT_LABEL:
|
2000-02-13 07:55:30 +03:00
|
|
|
get_component_label(fd, component);
|
1999-02-24 03:03:12 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_INIT_LABELS:
|
2000-02-13 07:55:30 +03:00
|
|
|
init_component_labels(fd, serial_number);
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_REWRITEPARITY:
|
|
|
|
printf("Initiating re-write of parity\n");
|
|
|
|
do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
|
|
|
|
"RAIDFRAME_REWRITEPARITY");
|
2000-01-05 06:02:41 +03:00
|
|
|
if (verbose) {
|
|
|
|
sleep(3); /* XXX give it time to get started */
|
|
|
|
printf("Parity Re-write status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
2000-05-28 04:49:35 +04:00
|
|
|
case RAIDFRAME_CHECK_RECON_STATUS_EXT:
|
2000-02-26 01:24:11 +03:00
|
|
|
check_status(fd,1);
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case RAIDFRAME_GET_INFO:
|
2001-07-10 05:30:52 +04:00
|
|
|
if (do_output)
|
|
|
|
rf_output_configuration(fd, dev_name);
|
|
|
|
else
|
|
|
|
rf_get_device_status(fd);
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
1999-03-02 06:13:59 +03:00
|
|
|
case RAIDFRAME_REBUILD_IN_PLACE:
|
2000-02-13 07:55:30 +03:00
|
|
|
rebuild_in_place(fd, component);
|
1999-03-02 06:13:59 +03:00
|
|
|
break;
|
1999-08-10 22:21:39 +04:00
|
|
|
case RAIDFRAME_CHECK_PARITY:
|
2000-02-13 07:55:30 +03:00
|
|
|
check_parity(fd, do_rewrite, dev_name);
|
1999-08-10 22:21:39 +04:00
|
|
|
break;
|
1998-11-13 07:34:02 +03:00
|
|
|
case RAIDFRAME_SHUTDOWN:
|
|
|
|
do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-01-05 06:02:41 +03:00
|
|
|
void
|
1998-11-13 07:34:02 +03:00
|
|
|
do_ioctl(fd, command, arg, ioctl_name)
|
|
|
|
int fd;
|
|
|
|
unsigned long command;
|
|
|
|
void *arg;
|
2000-05-23 04:33:13 +04:00
|
|
|
const char *ioctl_name;
|
1998-11-13 07:34:02 +03:00
|
|
|
{
|
|
|
|
if (ioctl(fd, command, arg) < 0) {
|
|
|
|
warn("ioctl (%s) failed", ioctl_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-02-24 03:03:12 +03:00
|
|
|
rf_configure(fd,config_file,force)
|
1998-11-13 07:34:02 +03:00
|
|
|
int fd;
|
|
|
|
char *config_file;
|
1999-02-24 03:03:12 +03:00
|
|
|
int force;
|
1998-11-13 07:34:02 +03:00
|
|
|
{
|
|
|
|
void *generic;
|
|
|
|
RF_Config_t cfg;
|
|
|
|
|
1999-08-15 07:18:19 +04:00
|
|
|
if (rf_MakeConfig( config_file, &cfg ) != 0) {
|
1998-11-13 07:34:02 +03:00
|
|
|
fprintf(stderr,"%s: unable to create RAIDframe %s\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname(), "configuration structure\n");
|
1998-11-13 07:34:02 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
cfg.force = force;
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
/*
|
2000-05-23 04:46:53 +04:00
|
|
|
* Note the extra level of redirection needed here, since
|
|
|
|
* what we really want to pass in is a pointer to the pointer to
|
|
|
|
* the configuration structure.
|
1998-11-13 07:34:02 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
generic = (void *) &cfg;
|
1999-03-02 06:13:59 +03:00
|
|
|
do_ioctl(fd, RAIDFRAME_CONFIGURE, &generic, "RAIDFRAME_CONFIGURE");
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
|
2000-05-23 04:46:53 +04:00
|
|
|
static const char *
|
1998-11-13 07:34:02 +03:00
|
|
|
device_status(status)
|
|
|
|
RF_DiskStatus_t status;
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case rf_ds_optimal:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("optimal");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_failed:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("failed");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_reconstructing:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("reconstructing");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_dist_spared:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("dist_spared");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_spared:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("spared");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_spare:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("spare");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
case rf_ds_used_spare:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("used_spare");
|
1998-11-13 07:34:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
2000-05-23 04:46:53 +04:00
|
|
|
return ("UNKNOWN");
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
2000-05-23 04:46:53 +04:00
|
|
|
/* NOTREACHED */
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rf_get_device_status(fd)
|
|
|
|
int fd;
|
|
|
|
{
|
|
|
|
RF_DeviceConfig_t device_config;
|
|
|
|
void *cfg_ptr;
|
1999-08-15 07:15:00 +04:00
|
|
|
int is_clean;
|
1998-11-13 07:34:02 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
cfg_ptr = &device_config;
|
|
|
|
|
|
|
|
do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr, "RAIDFRAME_GET_INFO");
|
|
|
|
|
|
|
|
printf("Components:\n");
|
|
|
|
for(i=0; i < device_config.ndevs; i++) {
|
|
|
|
printf("%20s: %s\n", device_config.devs[i].devname,
|
|
|
|
device_status(device_config.devs[i].status));
|
|
|
|
}
|
|
|
|
if (device_config.nspares > 0) {
|
|
|
|
printf("Spares:\n");
|
|
|
|
for(i=0; i < device_config.nspares; i++) {
|
1999-02-24 03:03:12 +03:00
|
|
|
printf("%20s: %s\n",
|
1998-11-13 07:34:02 +03:00
|
|
|
device_config.spares[i].devname,
|
|
|
|
device_status(device_config.spares[i].status));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("No spares.\n");
|
|
|
|
}
|
2000-02-26 01:24:11 +03:00
|
|
|
for(i=0; i < device_config.ndevs; i++) {
|
|
|
|
if (device_config.devs[i].status == rf_ds_optimal) {
|
|
|
|
get_component_label(fd, device_config.devs[i].devname);
|
|
|
|
} else {
|
|
|
|
printf("%s status is: %s. Skipping label.\n",
|
|
|
|
device_config.devs[i].devname,
|
|
|
|
device_status(device_config.devs[i].status));
|
|
|
|
}
|
|
|
|
}
|
2000-06-03 20:59:36 +04:00
|
|
|
|
2000-05-29 03:12:01 +04:00
|
|
|
if (device_config.nspares > 0) {
|
|
|
|
for(i=0; i < device_config.nspares; i++) {
|
|
|
|
if ((device_config.spares[i].status ==
|
|
|
|
rf_ds_optimal) ||
|
|
|
|
(device_config.spares[i].status ==
|
|
|
|
rf_ds_used_spare)) {
|
|
|
|
get_component_label(fd,
|
|
|
|
device_config.spares[i].devname);
|
|
|
|
} else {
|
|
|
|
printf("%s status is: %s. Skipping label.\n",
|
|
|
|
device_config.spares[i].devname,
|
|
|
|
device_status(device_config.spares[i].status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-03 20:59:36 +04:00
|
|
|
|
1999-08-15 07:15:00 +04:00
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_PARITY, &is_clean,
|
|
|
|
"RAIDFRAME_CHECK_PARITY");
|
|
|
|
if (is_clean) {
|
|
|
|
printf("Parity status: clean\n");
|
|
|
|
} else {
|
|
|
|
printf("Parity status: DIRTY\n");
|
|
|
|
}
|
2000-02-26 01:24:11 +03:00
|
|
|
check_status(fd,0);
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
|
2001-07-10 05:30:52 +04:00
|
|
|
static void
|
|
|
|
rf_output_configuration(fd, name)
|
|
|
|
int fd;
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
RF_DeviceConfig_t device_config;
|
|
|
|
void *cfg_ptr;
|
|
|
|
int i;
|
|
|
|
RF_ComponentLabel_t component_label;
|
|
|
|
void *label_ptr;
|
|
|
|
int component_num;
|
|
|
|
int num_cols;
|
|
|
|
|
|
|
|
cfg_ptr = &device_config;
|
|
|
|
|
|
|
|
printf("# raidctl config file for %s\n", name);
|
|
|
|
printf("\n");
|
|
|
|
do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr, "RAIDFRAME_GET_INFO");
|
|
|
|
|
|
|
|
printf("START array\n");
|
|
|
|
printf("# numRow numCol numSpare\n");
|
|
|
|
printf("%d %d %d\n", device_config.rows, device_config.cols,
|
|
|
|
device_config.nspares);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("START disks\n");
|
|
|
|
for(i=0; i < device_config.ndevs; i++)
|
|
|
|
printf("%s\n", device_config.devs[i].devname);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (device_config.nspares > 0) {
|
|
|
|
printf("START spare\n");
|
|
|
|
for(i=0; i < device_config.nspares; i++)
|
|
|
|
printf("%s\n", device_config.spares[i].devname);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i < device_config.ndevs; i++) {
|
|
|
|
if (device_config.devs[i].status == rf_ds_optimal)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == device_config.ndevs) {
|
|
|
|
printf("# WARNING: no optimal components; using %s\n",
|
|
|
|
device_config.devs[0].devname);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
get_component_number(fd, device_config.devs[i].devname,
|
|
|
|
&component_num, &num_cols);
|
|
|
|
memset(&component_label, 0, sizeof(RF_ComponentLabel_t));
|
|
|
|
component_label.row = component_num / num_cols;
|
|
|
|
component_label.column = component_num % num_cols;
|
|
|
|
label_ptr = &component_label;
|
|
|
|
do_ioctl(fd, RAIDFRAME_GET_COMPONENT_LABEL, &label_ptr,
|
|
|
|
"RAIDFRAME_GET_COMPONENT_LABEL");
|
|
|
|
|
|
|
|
printf("START layout\n");
|
|
|
|
printf(
|
|
|
|
"# sectPerSU SUsPerParityUnit SUsPerReconUnit RAID_level_%c\n",
|
|
|
|
(char) component_label.parityConfig);
|
|
|
|
printf("%d %d %d %c\n",
|
|
|
|
component_label.sectPerSU, component_label.SUsPerPU,
|
|
|
|
component_label.SUsPerRU, (char) component_label.parityConfig);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("START queue\n");
|
|
|
|
printf("fifo %d\n", device_config.maxqdepth);
|
|
|
|
}
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
static void
|
1999-03-02 06:13:59 +03:00
|
|
|
get_component_number(fd, component_name, component_number, num_columns)
|
1998-11-13 07:34:02 +03:00
|
|
|
int fd;
|
1999-03-02 06:13:59 +03:00
|
|
|
char *component_name;
|
|
|
|
int *component_number;
|
|
|
|
int *num_columns;
|
1998-11-13 07:34:02 +03:00
|
|
|
{
|
|
|
|
RF_DeviceConfig_t device_config;
|
|
|
|
void *cfg_ptr;
|
|
|
|
int i;
|
|
|
|
int found;
|
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
*component_number = -1;
|
1998-11-13 07:34:02 +03:00
|
|
|
|
|
|
|
/* Assuming a full path spec... */
|
|
|
|
cfg_ptr = &device_config;
|
|
|
|
do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
|
|
|
|
"RAIDFRAME_GET_INFO");
|
1999-03-02 06:13:59 +03:00
|
|
|
|
|
|
|
*num_columns = device_config.cols;
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
found = 0;
|
|
|
|
for(i=0; i < device_config.ndevs; i++) {
|
1999-03-02 06:13:59 +03:00
|
|
|
if (strncmp(component_name, device_config.devs[i].devname,
|
1998-11-13 07:34:02 +03:00
|
|
|
PATH_MAX)==0) {
|
|
|
|
found = 1;
|
1999-03-02 06:13:59 +03:00
|
|
|
*component_number = i;
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-29 03:12:01 +04:00
|
|
|
if (!found) { /* maybe it's a spare? */
|
|
|
|
for(i=0; i < device_config.nspares; i++) {
|
|
|
|
if (strncmp(component_name,
|
|
|
|
device_config.spares[i].devname,
|
|
|
|
PATH_MAX)==0) {
|
|
|
|
found = 1;
|
|
|
|
*component_number = i + device_config.ndevs;
|
2000-06-03 20:59:36 +04:00
|
|
|
/* the way spares are done should
|
|
|
|
really change... */
|
|
|
|
*num_columns = device_config.cols +
|
|
|
|
device_config.nspares;
|
2000-05-29 03:12:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
if (!found) {
|
2001-02-20 01:48:57 +03:00
|
|
|
fprintf(stderr,"%s: %s is not a component %s", getprogname(),
|
1999-03-02 06:13:59 +03:00
|
|
|
component_name, "of this device\n");
|
1998-11-13 07:34:02 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
1999-03-02 06:13:59 +03:00
|
|
|
}
|
1998-11-13 07:34:02 +03:00
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
static void
|
|
|
|
rf_fail_disk(fd, component_to_fail, do_recon)
|
|
|
|
int fd;
|
|
|
|
char *component_to_fail;
|
|
|
|
int do_recon;
|
|
|
|
{
|
|
|
|
struct rf_recon_req recon_request;
|
|
|
|
int component_num;
|
|
|
|
int num_cols;
|
|
|
|
|
|
|
|
get_component_number(fd, component_to_fail, &component_num, &num_cols);
|
|
|
|
|
|
|
|
recon_request.row = component_num / num_cols;
|
|
|
|
recon_request.col = component_num % num_cols;
|
1998-11-13 07:34:02 +03:00
|
|
|
if (do_recon) {
|
|
|
|
recon_request.flags = RF_FDFLAGS_RECON;
|
|
|
|
} else {
|
|
|
|
recon_request.flags = RF_FDFLAGS_NONE;
|
|
|
|
}
|
|
|
|
do_ioctl(fd, RAIDFRAME_FAIL_DISK, &recon_request,
|
|
|
|
"RAIDFRAME_FAIL_DISK");
|
2000-01-05 06:02:41 +03:00
|
|
|
if (do_recon && verbose) {
|
|
|
|
printf("Reconstruction status:\n");
|
|
|
|
sleep(3); /* XXX give reconstruction a chance to start */
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
1998-11-13 07:34:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-24 03:03:12 +03:00
|
|
|
static void
|
|
|
|
get_component_label(fd, component)
|
|
|
|
int fd;
|
|
|
|
char *component;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t component_label;
|
|
|
|
void *label_ptr;
|
|
|
|
int component_num;
|
1999-03-02 06:13:59 +03:00
|
|
|
int num_cols;
|
1999-02-24 03:03:12 +03:00
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
get_component_number(fd, component, &component_num, &num_cols);
|
1999-02-24 03:03:12 +03:00
|
|
|
|
|
|
|
memset( &component_label, 0, sizeof(RF_ComponentLabel_t));
|
1999-03-02 06:13:59 +03:00
|
|
|
component_label.row = component_num / num_cols;
|
|
|
|
component_label.column = component_num % num_cols;
|
1999-02-24 03:03:12 +03:00
|
|
|
|
|
|
|
label_ptr = &component_label;
|
|
|
|
do_ioctl( fd, RAIDFRAME_GET_COMPONENT_LABEL, &label_ptr,
|
|
|
|
"RAIDFRAME_GET_COMPONENT_LABEL");
|
|
|
|
|
|
|
|
printf("Component label for %s:\n",component);
|
2000-02-13 07:55:30 +03:00
|
|
|
|
2000-10-31 17:18:39 +03:00
|
|
|
printf(" Row: %d, Column: %d, Num Rows: %d, Num Columns: %d\n",
|
2000-02-13 07:55:30 +03:00
|
|
|
component_label.row, component_label.column,
|
|
|
|
component_label.num_rows, component_label.num_columns);
|
2000-10-31 17:18:39 +03:00
|
|
|
printf(" Version: %d, Serial Number: %d, Mod Counter: %d\n",
|
2000-02-13 07:55:30 +03:00
|
|
|
component_label.version, component_label.serial_number,
|
|
|
|
component_label.mod_counter);
|
2000-10-31 17:18:39 +03:00
|
|
|
printf(" Clean: %s, Status: %d\n",
|
2000-02-13 07:55:30 +03:00
|
|
|
component_label.clean ? "Yes" : "No",
|
|
|
|
component_label.status );
|
2000-10-31 17:18:39 +03:00
|
|
|
printf(" sectPerSU: %d, SUsPerPU: %d, SUsPerRU: %d\n",
|
2000-02-13 07:55:30 +03:00
|
|
|
component_label.sectPerSU, component_label.SUsPerPU,
|
|
|
|
component_label.SUsPerRU);
|
2000-10-31 17:18:39 +03:00
|
|
|
printf(" Queue size: %d, blocksize: %d, numBlocks: %d\n",
|
|
|
|
component_label.maxOutstanding, component_label.blockSize,
|
|
|
|
component_label.numBlocks);
|
|
|
|
printf(" RAID Level: %c\n", (char) component_label.parityConfig);
|
2000-02-13 07:55:30 +03:00
|
|
|
printf(" Autoconfig: %s\n",
|
|
|
|
component_label.autoconfigure ? "Yes" : "No" );
|
2000-03-23 17:50:36 +03:00
|
|
|
printf(" Root partition: %s\n",
|
|
|
|
component_label.root_partition ? "Yes" : "No" );
|
2000-02-13 07:55:30 +03:00
|
|
|
printf(" Last configured as: raid%d\n", component_label.last_unit );
|
1999-02-24 03:03:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_component_label(fd, component)
|
|
|
|
int fd;
|
|
|
|
char *component;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t component_label;
|
|
|
|
int component_num;
|
1999-03-02 06:13:59 +03:00
|
|
|
int num_cols;
|
1999-02-24 03:03:12 +03:00
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
get_component_number(fd, component, &component_num, &num_cols);
|
|
|
|
|
|
|
|
/* XXX This is currently here for testing, and future expandability */
|
1999-02-24 03:03:12 +03:00
|
|
|
|
|
|
|
component_label.version = 1;
|
|
|
|
component_label.serial_number = 123456;
|
|
|
|
component_label.mod_counter = 0;
|
1999-03-02 06:13:59 +03:00
|
|
|
component_label.row = component_num / num_cols;
|
|
|
|
component_label.column = component_num % num_cols;
|
1999-02-24 03:03:12 +03:00
|
|
|
component_label.num_rows = 0;
|
|
|
|
component_label.num_columns = 5;
|
|
|
|
component_label.clean = 0;
|
|
|
|
component_label.status = 1;
|
|
|
|
|
|
|
|
do_ioctl( fd, RAIDFRAME_SET_COMPONENT_LABEL, &component_label,
|
|
|
|
"RAIDFRAME_SET_COMPONENT_LABEL");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_component_labels(fd, serial_number)
|
|
|
|
int fd;
|
|
|
|
int serial_number;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t component_label;
|
|
|
|
|
|
|
|
component_label.version = 0;
|
|
|
|
component_label.serial_number = serial_number;
|
|
|
|
component_label.mod_counter = 0;
|
|
|
|
component_label.row = 0;
|
|
|
|
component_label.column = 0;
|
|
|
|
component_label.num_rows = 0;
|
|
|
|
component_label.num_columns = 0;
|
|
|
|
component_label.clean = 0;
|
|
|
|
component_label.status = 0;
|
|
|
|
|
|
|
|
do_ioctl( fd, RAIDFRAME_INIT_LABELS, &component_label,
|
|
|
|
"RAIDFRAME_SET_COMPONENT_LABEL");
|
|
|
|
}
|
|
|
|
|
2000-02-13 07:55:30 +03:00
|
|
|
static void
|
|
|
|
set_autoconfig(fd, raidID, autoconf)
|
|
|
|
int fd;
|
|
|
|
int raidID;
|
|
|
|
char *autoconf;
|
|
|
|
{
|
|
|
|
int auto_config;
|
|
|
|
int root_config;
|
|
|
|
|
|
|
|
auto_config = 0;
|
|
|
|
root_config = 0;
|
|
|
|
|
|
|
|
if (strncasecmp(autoconf,"root", 4) == 0) {
|
|
|
|
root_config = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strncasecmp(autoconf,"yes", 3) == 0) ||
|
|
|
|
root_config == 1) {
|
|
|
|
auto_config = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_ioctl(fd, RAIDFRAME_SET_AUTOCONFIG, &auto_config,
|
|
|
|
"RAIDFRAME_SET_AUTOCONFIG");
|
|
|
|
|
|
|
|
do_ioctl(fd, RAIDFRAME_SET_ROOT, &root_config,
|
|
|
|
"RAIDFRAME_SET_ROOT");
|
|
|
|
|
|
|
|
printf("raid%d: Autoconfigure: %s\n", raidID,
|
|
|
|
auto_config ? "Yes" : "No");
|
|
|
|
|
|
|
|
if (root_config == 1) {
|
|
|
|
printf("raid%d: Root: %s\n", raidID,
|
|
|
|
auto_config ? "Yes" : "No");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-24 03:03:12 +03:00
|
|
|
static void
|
|
|
|
add_hot_spare(fd, component)
|
|
|
|
int fd;
|
|
|
|
char *component;
|
|
|
|
{
|
1999-03-02 06:13:59 +03:00
|
|
|
RF_SingleComponent_t hot_spare;
|
1999-02-24 03:03:12 +03:00
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
hot_spare.row = 0;
|
|
|
|
hot_spare.column = 0;
|
|
|
|
strncpy(hot_spare.component_name, component,
|
|
|
|
sizeof(hot_spare.component_name));
|
1999-02-24 03:03:12 +03:00
|
|
|
|
|
|
|
do_ioctl( fd, RAIDFRAME_ADD_HOT_SPARE, &hot_spare,
|
|
|
|
"RAIDFRAME_ADD_HOT_SPARE");
|
1999-03-02 06:13:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_hot_spare(fd, component)
|
|
|
|
int fd;
|
|
|
|
char *component;
|
|
|
|
{
|
|
|
|
RF_SingleComponent_t hot_spare;
|
|
|
|
int component_num;
|
|
|
|
int num_cols;
|
|
|
|
|
|
|
|
get_component_number(fd, component, &component_num, &num_cols);
|
1999-02-24 03:03:12 +03:00
|
|
|
|
1999-03-02 06:13:59 +03:00
|
|
|
hot_spare.row = component_num / num_cols;
|
|
|
|
hot_spare.column = component_num % num_cols;
|
|
|
|
|
|
|
|
strncpy(hot_spare.component_name, component,
|
|
|
|
sizeof(hot_spare.component_name));
|
|
|
|
|
|
|
|
do_ioctl( fd, RAIDFRAME_REMOVE_HOT_SPARE, &hot_spare,
|
|
|
|
"RAIDFRAME_REMOVE_HOT_SPARE");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rebuild_in_place( fd, component )
|
|
|
|
int fd;
|
|
|
|
char *component;
|
|
|
|
{
|
|
|
|
RF_SingleComponent_t comp;
|
|
|
|
int component_num;
|
|
|
|
int num_cols;
|
|
|
|
|
|
|
|
get_component_number(fd, component, &component_num, &num_cols);
|
|
|
|
|
|
|
|
comp.row = 0;
|
|
|
|
comp.column = component_num;
|
|
|
|
strncpy(comp.component_name, component, sizeof(comp.component_name));
|
|
|
|
|
|
|
|
do_ioctl( fd, RAIDFRAME_REBUILD_IN_PLACE, &comp,
|
|
|
|
"RAIDFRAME_REBUILD_IN_PLACE");
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
printf("Reconstruction status:\n");
|
|
|
|
sleep(3); /* XXX give reconstruction a chance to start */
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_parity( fd, do_rewrite, dev_name )
|
|
|
|
int fd;
|
|
|
|
int do_rewrite;
|
|
|
|
char *dev_name;
|
|
|
|
{
|
|
|
|
int is_clean;
|
|
|
|
int percent_done;
|
|
|
|
|
|
|
|
is_clean = 0;
|
|
|
|
percent_done = 0;
|
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_PARITY, &is_clean,
|
|
|
|
"RAIDFRAME_CHECK_PARITY");
|
|
|
|
if (is_clean) {
|
|
|
|
printf("%s: Parity status: clean\n",dev_name);
|
|
|
|
} else {
|
|
|
|
printf("%s: Parity status: DIRTY\n",dev_name);
|
|
|
|
if (do_rewrite) {
|
|
|
|
printf("%s: Initiating re-write of parity\n",
|
|
|
|
dev_name);
|
|
|
|
do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
|
|
|
|
"RAIDFRAME_REWRITEPARITY");
|
|
|
|
sleep(3); /* XXX give it time to
|
|
|
|
get started. */
|
|
|
|
if (verbose) {
|
|
|
|
printf("Parity Re-write status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
|
2000-01-05 06:02:41 +03:00
|
|
|
} else {
|
|
|
|
do_ioctl(fd,
|
|
|
|
RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
|
|
|
|
&percent_done,
|
|
|
|
"RAIDFRAME_CHECK_PARITYREWRITE_STATUS"
|
|
|
|
);
|
|
|
|
while( percent_done < 100 ) {
|
2000-08-19 23:51:17 +04:00
|
|
|
sleep(3); /* wait a bit... */
|
2000-01-05 06:02:41 +03:00
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
|
|
|
|
&percent_done, "RAIDFRAME_CHECK_PARITYREWRITE_STATUS");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
printf("%s: Parity Re-write complete\n",
|
|
|
|
dev_name);
|
|
|
|
} else {
|
|
|
|
/* parity is wrong, and is not being fixed.
|
|
|
|
Exit w/ an error. */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-02-26 01:24:11 +03:00
|
|
|
check_status( fd, meter )
|
2000-01-05 06:02:41 +03:00
|
|
|
int fd;
|
2000-02-26 01:24:11 +03:00
|
|
|
int meter;
|
2000-01-05 06:02:41 +03:00
|
|
|
{
|
|
|
|
int recon_percent_done = 0;
|
|
|
|
int parity_percent_done = 0;
|
|
|
|
int copyback_percent_done = 0;
|
|
|
|
|
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_RECON_STATUS, &recon_percent_done,
|
|
|
|
"RAIDFRAME_CHECK_RECON_STATUS");
|
|
|
|
printf("Reconstruction is %d%% complete.\n", recon_percent_done);
|
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
|
|
|
|
&parity_percent_done,
|
|
|
|
"RAIDFRAME_CHECK_PARITYREWRITE_STATUS");
|
|
|
|
printf("Parity Re-write is %d%% complete.\n", parity_percent_done);
|
|
|
|
do_ioctl(fd, RAIDFRAME_CHECK_COPYBACK_STATUS, ©back_percent_done,
|
|
|
|
"RAIDFRAME_CHECK_COPYBACK_STATUS");
|
|
|
|
printf("Copyback is %d%% complete.\n", copyback_percent_done);
|
|
|
|
|
2000-02-26 01:24:11 +03:00
|
|
|
if (meter) {
|
|
|
|
/* These 3 should be mutually exclusive at this point */
|
|
|
|
if (recon_percent_done < 100) {
|
|
|
|
printf("Reconstruction status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
|
2000-02-26 01:24:11 +03:00
|
|
|
} else if (parity_percent_done < 100) {
|
|
|
|
printf("Parity Re-write status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
|
2000-02-26 01:24:11 +03:00
|
|
|
} else if (copyback_percent_done < 100) {
|
|
|
|
printf("Copyback status:\n");
|
2000-05-28 04:49:35 +04:00
|
|
|
do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
|
2000-02-26 01:24:11 +03:00
|
|
|
}
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-23 04:46:53 +04:00
|
|
|
const char *tbits = "|/-\\";
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
static void
|
2000-05-23 04:33:13 +04:00
|
|
|
do_meter(fd, option)
|
2000-01-05 06:02:41 +03:00
|
|
|
int fd;
|
2000-05-23 04:33:13 +04:00
|
|
|
u_long option;
|
2000-01-05 06:02:41 +03:00
|
|
|
{
|
|
|
|
int percent_done;
|
2000-05-28 04:49:35 +04:00
|
|
|
int last_value;
|
|
|
|
int start_value;
|
|
|
|
RF_ProgressInfo_t progressInfo;
|
|
|
|
void *pInfoPtr;
|
2000-01-05 06:02:41 +03:00
|
|
|
struct timeval start_time;
|
|
|
|
struct timeval last_time;
|
|
|
|
struct timeval current_time;
|
|
|
|
double elapsed;
|
|
|
|
int elapsed_sec;
|
|
|
|
int elapsed_usec;
|
2000-05-29 02:22:11 +04:00
|
|
|
int simple_eta,last_eta;
|
2000-01-05 06:02:41 +03:00
|
|
|
double rate;
|
2000-05-29 02:22:11 +04:00
|
|
|
int amount;
|
2000-01-05 06:02:41 +03:00
|
|
|
int tbit_value;
|
|
|
|
int wait_for_more_data;
|
|
|
|
char buffer[1024];
|
|
|
|
char bar_buffer[1024];
|
|
|
|
char eta_buffer[1024];
|
|
|
|
|
|
|
|
if (gettimeofday(&start_time,NULL)) {
|
2001-02-20 01:48:57 +03:00
|
|
|
fprintf(stderr,"%s: gettimeofday failed!?!?\n", getprogname());
|
2000-01-05 06:02:41 +03:00
|
|
|
exit(errno);
|
|
|
|
}
|
2000-05-28 04:49:35 +04:00
|
|
|
memset(&progressInfo, 0, sizeof(RF_ProgressInfo_t));
|
|
|
|
pInfoPtr=&progressInfo;
|
|
|
|
|
2000-01-05 06:02:41 +03:00
|
|
|
percent_done = 0;
|
2000-05-28 04:49:35 +04:00
|
|
|
do_ioctl(fd, option, &pInfoPtr, "");
|
|
|
|
last_value = progressInfo.completed;
|
|
|
|
start_value = last_value;
|
2000-01-05 06:02:41 +03:00
|
|
|
last_time = start_time;
|
|
|
|
current_time = start_time;
|
|
|
|
|
|
|
|
wait_for_more_data = 0;
|
|
|
|
tbit_value = 0;
|
2000-05-28 04:49:35 +04:00
|
|
|
while(progressInfo.completed < progressInfo.total) {
|
2000-01-05 06:02:41 +03:00
|
|
|
|
2000-05-28 04:49:35 +04:00
|
|
|
percent_done = (progressInfo.completed * 100) /
|
|
|
|
progressInfo.total;
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
get_bar(bar_buffer, percent_done, 40);
|
|
|
|
|
2000-05-29 02:22:11 +04:00
|
|
|
elapsed_sec = current_time.tv_sec - start_time.tv_sec;
|
|
|
|
elapsed_usec = current_time.tv_usec - start_time.tv_usec;
|
2000-01-05 06:02:41 +03:00
|
|
|
if (elapsed_usec < 0) {
|
|
|
|
elapsed_usec-=1000000;
|
|
|
|
elapsed_sec++;
|
|
|
|
}
|
2000-05-29 02:22:11 +04:00
|
|
|
|
2000-01-05 06:02:41 +03:00
|
|
|
elapsed = (double) elapsed_sec +
|
|
|
|
(double) elapsed_usec / 1000000.0;
|
2000-05-28 04:49:35 +04:00
|
|
|
|
2000-05-29 02:22:11 +04:00
|
|
|
amount = progressInfo.completed - start_value;
|
2000-05-28 04:49:35 +04:00
|
|
|
|
2000-01-05 06:02:41 +03:00
|
|
|
if (amount <= 0) { /* we don't do negatives (yet?) */
|
|
|
|
amount = 0;
|
|
|
|
wait_for_more_data = 1;
|
|
|
|
} else {
|
|
|
|
wait_for_more_data = 0;
|
|
|
|
}
|
2000-05-29 02:22:11 +04:00
|
|
|
|
2000-05-31 04:47:30 +04:00
|
|
|
if (elapsed == 0)
|
|
|
|
rate = 0.0;
|
|
|
|
else
|
|
|
|
rate = amount / elapsed;
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
if (rate > 0.0) {
|
2000-05-28 04:49:35 +04:00
|
|
|
simple_eta = (int) (((double)progressInfo.total -
|
2000-05-29 02:22:11 +04:00
|
|
|
(double) progressInfo.completed)
|
2000-05-28 04:49:35 +04:00
|
|
|
/ rate);
|
2000-01-05 06:02:41 +03:00
|
|
|
} else {
|
|
|
|
simple_eta = -1;
|
|
|
|
}
|
2000-05-28 04:49:35 +04:00
|
|
|
|
2000-01-05 06:02:41 +03:00
|
|
|
if (simple_eta <=0) {
|
|
|
|
simple_eta = last_eta;
|
|
|
|
} else {
|
|
|
|
last_eta = simple_eta;
|
|
|
|
}
|
|
|
|
|
2000-05-29 02:22:11 +04:00
|
|
|
get_time_string(eta_buffer, simple_eta);
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
snprintf(buffer,1024,"\r%3d%% |%s| ETA: %s %c",
|
|
|
|
percent_done,bar_buffer,eta_buffer,tbits[tbit_value]);
|
|
|
|
|
|
|
|
write(fileno(stdout),buffer,strlen(buffer));
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* resolution wasn't high enough... wait until we get another
|
|
|
|
timestamp and perhaps more "work" done. */
|
|
|
|
|
|
|
|
if (!wait_for_more_data) {
|
|
|
|
last_time = current_time;
|
2000-05-28 04:49:35 +04:00
|
|
|
last_value = progressInfo.completed;
|
2000-01-05 06:02:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (++tbit_value>3)
|
|
|
|
tbit_value = 0;
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
if (gettimeofday(¤t_time,NULL)) {
|
|
|
|
fprintf(stderr,"%s: gettimeofday failed!?!?\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname());
|
2000-01-05 06:02:41 +03:00
|
|
|
exit(errno);
|
|
|
|
}
|
|
|
|
|
2000-05-28 04:49:35 +04:00
|
|
|
do_ioctl( fd, option, &pInfoPtr, "");
|
2000-01-05 06:02:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
/* 40 '*''s per line, then 40 ' ''s line. */
|
|
|
|
/* If you've got a screen wider than 160 characters, "tough" */
|
|
|
|
|
|
|
|
#define STAR_MIDPOINT 4*40
|
|
|
|
const char stars[] = "****************************************"
|
|
|
|
"****************************************"
|
|
|
|
"****************************************"
|
|
|
|
"****************************************"
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
" ";
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_bar(string,percent,max_strlen)
|
|
|
|
char *string;
|
|
|
|
double percent;
|
|
|
|
int max_strlen;
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
if (max_strlen > STAR_MIDPOINT) {
|
|
|
|
max_strlen = STAR_MIDPOINT;
|
|
|
|
}
|
|
|
|
offset = STAR_MIDPOINT -
|
|
|
|
(int)((percent * max_strlen)/ 100);
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
|
|
|
snprintf(string,max_strlen,"%s",&stars[offset]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_time_string(string,simple_time)
|
|
|
|
char *string;
|
|
|
|
int simple_time;
|
|
|
|
{
|
|
|
|
int minutes, seconds, hours;
|
|
|
|
char hours_buffer[5];
|
|
|
|
char minutes_buffer[5];
|
|
|
|
char seconds_buffer[5];
|
|
|
|
|
|
|
|
if (simple_time >= 0) {
|
|
|
|
|
|
|
|
minutes = (int) simple_time / 60;
|
|
|
|
seconds = ((int)simple_time - 60*minutes);
|
|
|
|
hours = minutes / 60;
|
|
|
|
minutes = minutes - 60*hours;
|
|
|
|
|
|
|
|
if (hours > 0) {
|
|
|
|
snprintf(hours_buffer,5,"%02d:",hours);
|
|
|
|
} else {
|
|
|
|
snprintf(hours_buffer,5," ");
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(minutes_buffer,5,"%02d:",minutes);
|
|
|
|
snprintf(seconds_buffer,5,"%02d",seconds);
|
|
|
|
snprintf(string,1024,"%s%s%s",
|
|
|
|
hours_buffer, minutes_buffer, seconds_buffer);
|
|
|
|
} else {
|
|
|
|
snprintf(string,1024," --:--");
|
|
|
|
}
|
|
|
|
|
1999-02-24 03:03:12 +03:00
|
|
|
}
|
|
|
|
|
1998-11-13 07:34:02 +03:00
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
2001-02-20 01:48:57 +03:00
|
|
|
const char *progname = getprogname();
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: %s [-v] -a component dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -A yes | no | root dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -B dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -c config_file dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -C config_file dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -f component dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -F component dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -g component dev\n", progname);
|
2001-07-10 05:30:52 +04:00
|
|
|
fprintf(stderr, " %s [-v] -G dev\n", progname);
|
2001-02-20 01:48:57 +03:00
|
|
|
fprintf(stderr, " %s [-v] -i dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -I serial_number dev\n", progname);
|
2002-11-16 20:22:36 +03:00
|
|
|
fprintf(stderr, " %s [-v] -p dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -P dev\n", progname);
|
2001-02-20 01:48:57 +03:00
|
|
|
fprintf(stderr, " %s [-v] -r component dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -R component dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -s dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -S dev\n", progname);
|
|
|
|
fprintf(stderr, " %s [-v] -u dev\n", progname);
|
1998-11-13 07:34:02 +03:00
|
|
|
exit(1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|