Home | History | Annotate | Line # | Download | only in raidctl
raidctl.c revision 1.6
      1  1.6   oster /*      $NetBSD: raidctl.c,v 1.6 1999/03/02 03:13:59 oster Exp $   */
      2  1.1   oster /*-
      3  1.1   oster  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
      4  1.1   oster  * All rights reserved.
      5  1.1   oster  *
      6  1.1   oster  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1   oster  * by Greg Oster
      8  1.1   oster  *
      9  1.1   oster  * Redistribution and use in source and binary forms, with or without
     10  1.1   oster  * modification, are permitted provided that the following conditions
     11  1.1   oster  * are met:
     12  1.1   oster  * 1. Redistributions of source code must retain the above copyright
     13  1.1   oster  *    notice, this list of conditions and the following disclaimer.
     14  1.1   oster  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   oster  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   oster  *    documentation and/or other materials provided with the distribution.
     17  1.1   oster  * 3. All advertising materials mentioning features or use of this software
     18  1.1   oster  *    must display the following acknowledgement:
     19  1.1   oster  *        This product includes software developed by the NetBSD
     20  1.1   oster  *        Foundation, Inc. and its contributors.
     21  1.1   oster  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  1.1   oster  *    contributors may be used to endorse or promote products derived
     23  1.1   oster  *    from this software without specific prior written permission.
     24  1.1   oster  *
     25  1.1   oster  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.1   oster  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1   oster  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1   oster  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.1   oster  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1   oster  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1   oster  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1   oster  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1   oster  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1   oster  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1   oster  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1   oster  */
     37  1.1   oster 
     38  1.1   oster /*
     39  1.1   oster 
     40  1.1   oster    This program is a re-write of the original rf_ctrl program
     41  1.1   oster    distributed by CMU with RAIDframe 1.1.
     42  1.1   oster 
     43  1.1   oster    This program is the user-land interface to the RAIDframe kernel
     44  1.1   oster    driver in NetBSD.
     45  1.1   oster 
     46  1.1   oster  */
     47  1.1   oster 
     48  1.1   oster #include <sys/param.h>
     49  1.1   oster #include <sys/ioctl.h>
     50  1.1   oster #include <sys/stat.h>
     51  1.1   oster #include <util.h>
     52  1.1   oster #include <stdio.h>
     53  1.1   oster #include <fcntl.h>
     54  1.1   oster #include <ctype.h>
     55  1.1   oster #include <err.h>
     56  1.2  mjacob #include <errno.h>
     57  1.1   oster #include <sys/types.h>
     58  1.1   oster #include <string.h>
     59  1.1   oster #include <sys/disklabel.h>
     60  1.1   oster #include <machine/disklabel.h>
     61  1.5   oster #include <stdlib.h>
     62  1.3   oster #include <unistd.h>
     63  1.3   oster 
     64  1.1   oster #include "rf_raidframe.h"
     65  1.1   oster 
     66  1.1   oster extern  char *__progname;
     67  1.1   oster 
     68  1.1   oster int     main __P((int, char *[]));
     69  1.1   oster static  void do_ioctl __P((int, unsigned long, void *, char *));
     70  1.5   oster static  void rf_configure __P((int, char*, int));
     71  1.1   oster static  char *device_status __P((RF_DiskStatus_t));
     72  1.1   oster static  void rf_get_device_status __P((int));
     73  1.6   oster static  void get_component_number __P((int, char *, int *, int *));
     74  1.1   oster static  void rf_fail_disk __P((int, char *, int));
     75  1.1   oster static  void usage __P((void));
     76  1.5   oster static  void get_component_label __P((int, char *));
     77  1.5   oster static  void set_component_label __P((int, char *));
     78  1.5   oster static  void init_component_labels __P((int, int));
     79  1.5   oster static  void add_hot_spare __P((int, char *));
     80  1.6   oster static  void remove_hot_spare __P((int, char *));
     81  1.6   oster static  void rebuild_in_place __P((int, char *));
     82  1.1   oster 
     83  1.1   oster int
     84  1.1   oster main(argc,argv)
     85  1.1   oster 	int argc;
     86  1.1   oster 	char *argv[];
     87  1.1   oster {
     88  1.1   oster 	extern char *optarg;
     89  1.1   oster 	extern int optind;
     90  1.1   oster 	int ch;
     91  1.1   oster 	int num_options;
     92  1.1   oster 	unsigned long action;
     93  1.1   oster 	char config_filename[PATH_MAX];
     94  1.1   oster 	char dev_name[PATH_MAX];
     95  1.1   oster 	char name[PATH_MAX];
     96  1.5   oster 	char component[PATH_MAX];
     97  1.1   oster 	int do_recon;
     98  1.1   oster 	int raidID;
     99  1.1   oster 	int rawpart;
    100  1.1   oster 	int recon_percent_done;
    101  1.5   oster 	int serial_number;
    102  1.1   oster 	struct stat st;
    103  1.1   oster 	int fd;
    104  1.5   oster 	int force;
    105  1.1   oster 
    106  1.1   oster 	num_options = 0;
    107  1.1   oster 	action = 0;
    108  1.1   oster 	do_recon = 0;
    109  1.5   oster 	force = 0;
    110  1.1   oster 
    111  1.6   oster 	while ((ch = getopt(argc, argv, "a:Bc:C:f:F:g:iI:l:r:R:sSu")) != -1)
    112  1.1   oster 		switch(ch) {
    113  1.5   oster 		case 'a':
    114  1.5   oster 			action = RAIDFRAME_ADD_HOT_SPARE;
    115  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    116  1.5   oster 			num_options++;
    117  1.5   oster 			break;
    118  1.6   oster 		case 'B':
    119  1.6   oster 			action = RAIDFRAME_COPYBACK;
    120  1.6   oster 			num_options++;
    121  1.6   oster 			break;
    122  1.1   oster 		case 'c':
    123  1.6   oster 			action = RAIDFRAME_CONFIGURE;
    124  1.1   oster 			strncpy(config_filename,optarg,PATH_MAX);
    125  1.6   oster 			force = 0;
    126  1.1   oster 			num_options++;
    127  1.1   oster 			break;
    128  1.1   oster 		case 'C':
    129  1.6   oster 			strncpy(config_filename,optarg,PATH_MAX);
    130  1.6   oster 			action = RAIDFRAME_CONFIGURE;
    131  1.6   oster 			force = 1;
    132  1.1   oster 			num_options++;
    133  1.1   oster 			break;
    134  1.1   oster 		case 'f':
    135  1.1   oster 			action = RAIDFRAME_FAIL_DISK;
    136  1.6   oster 			strncpy(component, optarg, PATH_MAX);
    137  1.1   oster 			do_recon = 0;
    138  1.1   oster 			num_options++;
    139  1.1   oster 			break;
    140  1.1   oster 		case 'F':
    141  1.1   oster 			action = RAIDFRAME_FAIL_DISK;
    142  1.6   oster 			strncpy(component, optarg, PATH_MAX);
    143  1.1   oster 			do_recon = 1;
    144  1.5   oster 			num_options++;
    145  1.5   oster 			break;
    146  1.5   oster 		case 'g':
    147  1.5   oster 			action = RAIDFRAME_GET_COMPONENT_LABEL;
    148  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    149  1.5   oster 			num_options++;
    150  1.5   oster 			break;
    151  1.6   oster 		case 'i':
    152  1.6   oster 			action = RAIDFRAME_REWRITEPARITY;
    153  1.6   oster 			num_options++;
    154  1.6   oster 			break;
    155  1.5   oster 		case 'I':
    156  1.5   oster 			action = RAIDFRAME_INIT_LABELS;
    157  1.5   oster 			serial_number = atoi(optarg);
    158  1.5   oster 			num_options++;
    159  1.5   oster 			break;
    160  1.6   oster 		case 'l':
    161  1.5   oster 			action = RAIDFRAME_SET_COMPONENT_LABEL;
    162  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    163  1.1   oster 			num_options++;
    164  1.1   oster 			break;
    165  1.1   oster 		case 'r':
    166  1.6   oster 			action = RAIDFRAME_REMOVE_HOT_SPARE;
    167  1.6   oster 			strncpy(component, optarg, PATH_MAX);
    168  1.1   oster 			num_options++;
    169  1.1   oster 			break;
    170  1.1   oster 		case 'R':
    171  1.6   oster 			strncpy(component,optarg,PATH_MAX);
    172  1.6   oster 			action = RAIDFRAME_REBUILD_IN_PLACE;
    173  1.1   oster 			num_options++;
    174  1.1   oster 			break;
    175  1.1   oster 		case 's':
    176  1.1   oster 			action = RAIDFRAME_GET_INFO;
    177  1.1   oster 			num_options++;
    178  1.1   oster 			break;
    179  1.6   oster 		case 'S':
    180  1.6   oster 			action = RAIDFRAME_CHECKRECON;
    181  1.6   oster 			num_options++;
    182  1.6   oster 			break;
    183  1.1   oster 		case 'u':
    184  1.1   oster 			action = RAIDFRAME_SHUTDOWN;
    185  1.1   oster 			num_options++;
    186  1.1   oster 			break;
    187  1.1   oster 		default:
    188  1.1   oster 			usage();
    189  1.1   oster 		}
    190  1.1   oster 	argc -= optind;
    191  1.1   oster 	argv += optind;
    192  1.1   oster 
    193  1.1   oster 	if ((num_options > 1) || (argc == NULL))
    194  1.1   oster 		usage();
    195  1.1   oster 
    196  1.1   oster 	strncpy(name,argv[0],PATH_MAX);
    197  1.1   oster 
    198  1.1   oster 	if ((name[0] == '/') || (name[0] == '.')) {
    199  1.1   oster 		/* they've (apparently) given a full path... */
    200  1.1   oster 		strncpy(dev_name, name, PATH_MAX);
    201  1.1   oster 	} else {
    202  1.1   oster 		if (isdigit(name[strlen(name)-1])) {
    203  1.1   oster 			rawpart = getrawpartition();
    204  1.1   oster 			snprintf(dev_name,PATH_MAX,"/dev/%s%c",name,
    205  1.1   oster 				 'a'+rawpart);
    206  1.1   oster 		} else {
    207  1.1   oster 			snprintf(dev_name,PATH_MAX,"/dev/%s",name);
    208  1.1   oster 		}
    209  1.1   oster 	}
    210  1.1   oster 
    211  1.1   oster 	if (stat(dev_name, &st) != 0) {
    212  1.1   oster 		fprintf(stderr,"%s: stat failure on: %s\n",
    213  1.1   oster 			__progname,dev_name);
    214  1.1   oster 		return (errno);
    215  1.1   oster 	}
    216  1.1   oster 	if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
    217  1.1   oster 		fprintf(stderr,"%s: invalid device: %s\n",
    218  1.1   oster 			__progname,dev_name);
    219  1.1   oster 		return (EINVAL);
    220  1.1   oster 	}
    221  1.1   oster 
    222  1.1   oster 	raidID = RF_DEV2RAIDID(st.st_rdev);
    223  1.1   oster 
    224  1.1   oster 	if ((fd = open( dev_name, O_RDWR, 0640)) < 0) {
    225  1.1   oster 		fprintf(stderr, "%s: unable to open device file: %s\n",
    226  1.1   oster 			__progname, dev_name);
    227  1.1   oster 		exit(1);
    228  1.1   oster 	}
    229  1.1   oster 
    230  1.1   oster 
    231  1.1   oster 	switch(action) {
    232  1.5   oster 	case RAIDFRAME_ADD_HOT_SPARE:
    233  1.5   oster 		add_hot_spare(fd,component);
    234  1.5   oster 		break;
    235  1.6   oster 	case RAIDFRAME_REMOVE_HOT_SPARE:
    236  1.6   oster 		remove_hot_spare(fd,component);
    237  1.6   oster 		break;
    238  1.1   oster 	case RAIDFRAME_CONFIGURE:
    239  1.5   oster 		rf_configure(fd, config_filename,force);
    240  1.1   oster 		break;
    241  1.1   oster 	case RAIDFRAME_COPYBACK:
    242  1.1   oster 		printf("Copyback.\n");
    243  1.1   oster 		do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
    244  1.1   oster 		break;
    245  1.1   oster 	case RAIDFRAME_FAIL_DISK:
    246  1.5   oster 		rf_fail_disk(fd,component,do_recon);
    247  1.5   oster 		break;
    248  1.5   oster 	case RAIDFRAME_SET_COMPONENT_LABEL:
    249  1.5   oster 		set_component_label(fd,component);
    250  1.5   oster 		break;
    251  1.5   oster 	case RAIDFRAME_GET_COMPONENT_LABEL:
    252  1.5   oster 		get_component_label(fd,component);
    253  1.5   oster 		break;
    254  1.5   oster 	case RAIDFRAME_INIT_LABELS:
    255  1.5   oster 		init_component_labels(fd,serial_number);
    256  1.1   oster 		break;
    257  1.1   oster 	case RAIDFRAME_REWRITEPARITY:
    258  1.1   oster 		printf("Initiating re-write of parity\n");
    259  1.1   oster 		do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
    260  1.1   oster 			 "RAIDFRAME_REWRITEPARITY");
    261  1.1   oster 		break;
    262  1.1   oster 	case RAIDFRAME_CHECKRECON:
    263  1.1   oster 		do_ioctl(fd, RAIDFRAME_CHECKRECON, &recon_percent_done,
    264  1.1   oster 			 "RAIDFRAME_CHECKRECON");
    265  1.1   oster 		printf("Reconstruction is %d%% complete.\n",
    266  1.1   oster 		       recon_percent_done);
    267  1.1   oster 		break;
    268  1.1   oster 	case RAIDFRAME_GET_INFO:
    269  1.1   oster 		rf_get_device_status(fd);
    270  1.1   oster 		break;
    271  1.6   oster 	case RAIDFRAME_REBUILD_IN_PLACE:
    272  1.6   oster 		rebuild_in_place(fd,component);
    273  1.6   oster 		break;
    274  1.1   oster 	case RAIDFRAME_SHUTDOWN:
    275  1.1   oster 		do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
    276  1.1   oster 		break;
    277  1.1   oster 	default:
    278  1.1   oster 		break;
    279  1.1   oster 	}
    280  1.1   oster 
    281  1.1   oster 	close(fd);
    282  1.1   oster 	exit(0);
    283  1.1   oster }
    284  1.1   oster 
    285  1.1   oster static void
    286  1.1   oster do_ioctl(fd, command, arg, ioctl_name)
    287  1.1   oster 	int fd;
    288  1.1   oster 	unsigned long command;
    289  1.1   oster 	void *arg;
    290  1.1   oster 	char *ioctl_name;
    291  1.1   oster {
    292  1.1   oster 	if (ioctl(fd, command, arg) < 0) {
    293  1.1   oster 		warn("ioctl (%s) failed", ioctl_name);
    294  1.1   oster 		exit(1);
    295  1.1   oster 	}
    296  1.1   oster }
    297  1.1   oster 
    298  1.1   oster 
    299  1.1   oster static void
    300  1.5   oster rf_configure(fd,config_file,force)
    301  1.1   oster 	int fd;
    302  1.1   oster 	char *config_file;
    303  1.5   oster 	int force;
    304  1.1   oster {
    305  1.1   oster 	void *generic;
    306  1.1   oster 	RF_Config_t cfg;
    307  1.1   oster 
    308  1.1   oster 	if (rf_MakeConfig( config_file, &cfg ) < 0) {
    309  1.1   oster 		fprintf(stderr,"%s: unable to create RAIDframe %s\n",
    310  1.1   oster 			__progname, "configuration structure\n");
    311  1.1   oster 		exit(1);
    312  1.1   oster 	}
    313  1.1   oster 
    314  1.6   oster 	cfg.force = force;
    315  1.6   oster 
    316  1.1   oster 	/*
    317  1.1   oster 
    318  1.1   oster 	   Note the extra level of redirection needed here, since
    319  1.1   oster 	   what we really want to pass in is a pointer to the pointer to
    320  1.1   oster 	   the configuration structure.
    321  1.1   oster 
    322  1.1   oster 	 */
    323  1.1   oster 
    324  1.1   oster 	generic = (void *) &cfg;
    325  1.6   oster 	do_ioctl(fd, RAIDFRAME_CONFIGURE, &generic, "RAIDFRAME_CONFIGURE");
    326  1.1   oster }
    327  1.1   oster 
    328  1.1   oster static char *
    329  1.1   oster device_status(status)
    330  1.1   oster 	RF_DiskStatus_t status;
    331  1.1   oster {
    332  1.1   oster 	static char status_string[256];
    333  1.1   oster 
    334  1.1   oster 	switch (status) {
    335  1.1   oster 	case rf_ds_optimal:
    336  1.1   oster 		strcpy(status_string,"optimal");
    337  1.1   oster 		break;
    338  1.1   oster 	case rf_ds_failed:
    339  1.1   oster 		strcpy(status_string,"failed");
    340  1.1   oster 		break;
    341  1.1   oster 	case rf_ds_reconstructing:
    342  1.1   oster 		strcpy(status_string,"reconstructing");
    343  1.1   oster 		break;
    344  1.1   oster 	case rf_ds_dist_spared:
    345  1.1   oster 		strcpy(status_string,"dist_spared");
    346  1.1   oster 		break;
    347  1.1   oster 	case rf_ds_spared:
    348  1.1   oster 		strcpy(status_string,"spared");
    349  1.1   oster 		break;
    350  1.1   oster 	case rf_ds_spare:
    351  1.1   oster 		strcpy(status_string,"spare");
    352  1.1   oster 		break;
    353  1.1   oster 	case rf_ds_used_spare:
    354  1.1   oster 		strcpy(status_string,"used_spare");
    355  1.1   oster 		break;
    356  1.1   oster 	default:
    357  1.1   oster 		strcpy(status_string,"UNKNOWN");
    358  1.1   oster 		break;
    359  1.1   oster 	}
    360  1.1   oster 	return(status_string);
    361  1.1   oster }
    362  1.1   oster 
    363  1.1   oster static void
    364  1.1   oster rf_get_device_status(fd)
    365  1.1   oster 	int fd;
    366  1.1   oster {
    367  1.1   oster 	RF_DeviceConfig_t device_config;
    368  1.1   oster 	void *cfg_ptr;
    369  1.1   oster 	int i;
    370  1.1   oster 
    371  1.1   oster 	cfg_ptr = &device_config;
    372  1.1   oster 
    373  1.1   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr, "RAIDFRAME_GET_INFO");
    374  1.1   oster 
    375  1.1   oster 	printf("Components:\n");
    376  1.1   oster 	for(i=0; i < device_config.ndevs; i++) {
    377  1.1   oster 		printf("%20s: %s\n", device_config.devs[i].devname,
    378  1.1   oster 		       device_status(device_config.devs[i].status));
    379  1.1   oster 	}
    380  1.1   oster 	if (device_config.nspares > 0) {
    381  1.1   oster 		printf("Spares:\n");
    382  1.1   oster 		for(i=0; i < device_config.nspares; i++) {
    383  1.5   oster 			printf("%20s: %s\n",
    384  1.1   oster 			       device_config.spares[i].devname,
    385  1.1   oster 			       device_status(device_config.spares[i].status));
    386  1.1   oster 		}
    387  1.1   oster 	} else {
    388  1.1   oster 		printf("No spares.\n");
    389  1.1   oster 	}
    390  1.1   oster }
    391  1.1   oster 
    392  1.1   oster static void
    393  1.6   oster get_component_number(fd, component_name, component_number, num_columns)
    394  1.1   oster 	int fd;
    395  1.6   oster 	char *component_name;
    396  1.6   oster 	int *component_number;
    397  1.6   oster 	int *num_columns;
    398  1.1   oster {
    399  1.1   oster 	RF_DeviceConfig_t device_config;
    400  1.1   oster 	void *cfg_ptr;
    401  1.1   oster 	int i;
    402  1.1   oster 	int found;
    403  1.1   oster 
    404  1.6   oster 	*component_number = -1;
    405  1.1   oster 
    406  1.1   oster 	/* Assuming a full path spec... */
    407  1.1   oster 	cfg_ptr = &device_config;
    408  1.1   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
    409  1.1   oster 		 "RAIDFRAME_GET_INFO");
    410  1.6   oster 
    411  1.6   oster 	*num_columns = device_config.cols;
    412  1.6   oster 
    413  1.1   oster 	found = 0;
    414  1.1   oster 	for(i=0; i < device_config.ndevs; i++) {
    415  1.6   oster 		if (strncmp(component_name, device_config.devs[i].devname,
    416  1.1   oster 			    PATH_MAX)==0) {
    417  1.1   oster 			found = 1;
    418  1.6   oster 			*component_number = i;
    419  1.1   oster 		}
    420  1.1   oster 	}
    421  1.1   oster 	if (!found) {
    422  1.6   oster 		fprintf(stderr,"%s: %s is not a component %s", __progname,
    423  1.6   oster 			component_name, "of this device\n");
    424  1.1   oster 		exit(1);
    425  1.1   oster 	}
    426  1.6   oster }
    427  1.6   oster 
    428  1.6   oster static void
    429  1.6   oster rf_fail_disk(fd, component_to_fail, do_recon)
    430  1.6   oster 	int fd;
    431  1.6   oster 	char *component_to_fail;
    432  1.6   oster 	int do_recon;
    433  1.6   oster {
    434  1.6   oster 	struct rf_recon_req recon_request;
    435  1.6   oster 	int component_num;
    436  1.6   oster 	int num_cols;
    437  1.6   oster 
    438  1.6   oster 	get_component_number(fd, component_to_fail, &component_num, &num_cols);
    439  1.1   oster 
    440  1.6   oster 	recon_request.row = component_num / num_cols;
    441  1.6   oster 	recon_request.col = component_num % num_cols;
    442  1.1   oster 	if (do_recon) {
    443  1.1   oster 		recon_request.flags = RF_FDFLAGS_RECON;
    444  1.1   oster 	} else {
    445  1.1   oster 		recon_request.flags = RF_FDFLAGS_NONE;
    446  1.1   oster 	}
    447  1.1   oster 	do_ioctl(fd, RAIDFRAME_FAIL_DISK, &recon_request,
    448  1.1   oster 		 "RAIDFRAME_FAIL_DISK");
    449  1.1   oster }
    450  1.1   oster 
    451  1.1   oster static void
    452  1.5   oster get_component_label(fd, component)
    453  1.5   oster 	int fd;
    454  1.5   oster 	char *component;
    455  1.5   oster {
    456  1.5   oster 	RF_ComponentLabel_t component_label;
    457  1.5   oster 	void *label_ptr;
    458  1.5   oster 	int component_num;
    459  1.6   oster 	int num_cols;
    460  1.5   oster 
    461  1.6   oster 	get_component_number(fd, component, &component_num, &num_cols);
    462  1.5   oster 
    463  1.5   oster 	memset( &component_label, 0, sizeof(RF_ComponentLabel_t));
    464  1.6   oster 	component_label.row = component_num / num_cols;
    465  1.6   oster 	component_label.column = component_num % num_cols;
    466  1.5   oster 
    467  1.5   oster 	label_ptr = &component_label;
    468  1.5   oster 	do_ioctl( fd, RAIDFRAME_GET_COMPONENT_LABEL, &label_ptr,
    469  1.5   oster 		  "RAIDFRAME_GET_COMPONENT_LABEL");
    470  1.5   oster 
    471  1.5   oster 	printf("Component label for %s:\n",component);
    472  1.5   oster 	printf("Version: %d\n",component_label.version);
    473  1.5   oster 	printf("Serial Number: %d\n",component_label.serial_number);
    474  1.5   oster 	printf("Mod counter: %d\n",component_label.mod_counter);
    475  1.5   oster 	printf("Row: %d\n", component_label.row);
    476  1.5   oster 	printf("Column: %d\n", component_label.column);
    477  1.5   oster 	printf("Num Rows: %d\n", component_label.num_rows);
    478  1.5   oster 	printf("Num Columns: %d\n", component_label.num_columns);
    479  1.5   oster 	printf("Clean: %d\n", component_label.clean);
    480  1.5   oster 	printf("Status: %s\n", device_status(component_label.status));
    481  1.5   oster }
    482  1.5   oster 
    483  1.5   oster static void
    484  1.5   oster set_component_label(fd, component)
    485  1.5   oster 	int fd;
    486  1.5   oster 	char *component;
    487  1.5   oster {
    488  1.5   oster 	RF_ComponentLabel_t component_label;
    489  1.5   oster 	int component_num;
    490  1.6   oster 	int num_cols;
    491  1.5   oster 
    492  1.6   oster 	get_component_number(fd, component, &component_num, &num_cols);
    493  1.6   oster 
    494  1.6   oster 	/* XXX This is currently here for testing, and future expandability */
    495  1.5   oster 
    496  1.5   oster 	component_label.version = 1;
    497  1.5   oster 	component_label.serial_number = 123456;
    498  1.5   oster 	component_label.mod_counter = 0;
    499  1.6   oster 	component_label.row = component_num / num_cols;
    500  1.6   oster 	component_label.column = component_num % num_cols;
    501  1.5   oster 	component_label.num_rows = 0;
    502  1.5   oster 	component_label.num_columns = 5;
    503  1.5   oster 	component_label.clean = 0;
    504  1.5   oster 	component_label.status = 1;
    505  1.5   oster 
    506  1.5   oster 	do_ioctl( fd, RAIDFRAME_SET_COMPONENT_LABEL, &component_label,
    507  1.5   oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    508  1.5   oster }
    509  1.5   oster 
    510  1.5   oster 
    511  1.5   oster static void
    512  1.5   oster init_component_labels(fd, serial_number)
    513  1.5   oster 	int fd;
    514  1.5   oster 	int serial_number;
    515  1.5   oster {
    516  1.5   oster 	RF_ComponentLabel_t component_label;
    517  1.5   oster 
    518  1.5   oster 	component_label.version = 0;
    519  1.5   oster 	component_label.serial_number = serial_number;
    520  1.5   oster 	component_label.mod_counter = 0;
    521  1.5   oster 	component_label.row = 0;
    522  1.5   oster 	component_label.column = 0;
    523  1.5   oster 	component_label.num_rows = 0;
    524  1.5   oster 	component_label.num_columns = 0;
    525  1.5   oster 	component_label.clean = 0;
    526  1.5   oster 	component_label.status = 0;
    527  1.5   oster 
    528  1.5   oster 	do_ioctl( fd, RAIDFRAME_INIT_LABELS, &component_label,
    529  1.5   oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    530  1.5   oster }
    531  1.5   oster 
    532  1.5   oster static void
    533  1.5   oster add_hot_spare(fd, component)
    534  1.5   oster 	int fd;
    535  1.5   oster 	char *component;
    536  1.5   oster {
    537  1.6   oster 	RF_SingleComponent_t hot_spare;
    538  1.5   oster 
    539  1.6   oster 	hot_spare.row = 0;
    540  1.6   oster 	hot_spare.column = 0;
    541  1.6   oster 	strncpy(hot_spare.component_name, component,
    542  1.6   oster 		sizeof(hot_spare.component_name));
    543  1.5   oster 
    544  1.5   oster 	do_ioctl( fd, RAIDFRAME_ADD_HOT_SPARE, &hot_spare,
    545  1.5   oster 		  "RAIDFRAME_ADD_HOT_SPARE");
    546  1.6   oster }
    547  1.6   oster 
    548  1.6   oster static void
    549  1.6   oster remove_hot_spare(fd, component)
    550  1.6   oster 	int fd;
    551  1.6   oster 	char *component;
    552  1.6   oster {
    553  1.6   oster 	RF_SingleComponent_t hot_spare;
    554  1.6   oster 	int component_num;
    555  1.6   oster 	int num_cols;
    556  1.5   oster 
    557  1.6   oster 	get_component_number(fd, component, &component_num, &num_cols);
    558  1.6   oster 
    559  1.6   oster 	hot_spare.row = component_num / num_cols;
    560  1.6   oster 	hot_spare.column = component_num % num_cols;
    561  1.6   oster 
    562  1.6   oster 	strncpy(hot_spare.component_name, component,
    563  1.6   oster 		sizeof(hot_spare.component_name));
    564  1.6   oster 
    565  1.6   oster 	do_ioctl( fd, RAIDFRAME_REMOVE_HOT_SPARE, &hot_spare,
    566  1.6   oster 		  "RAIDFRAME_REMOVE_HOT_SPARE");
    567  1.6   oster }
    568  1.6   oster 
    569  1.6   oster static void
    570  1.6   oster rebuild_in_place( fd, component )
    571  1.6   oster 	int fd;
    572  1.6   oster 	char *component;
    573  1.6   oster {
    574  1.6   oster 	RF_SingleComponent_t comp;
    575  1.6   oster 	int component_num;
    576  1.6   oster 	int num_cols;
    577  1.6   oster 
    578  1.6   oster 	get_component_number(fd, component, &component_num, &num_cols);
    579  1.6   oster 
    580  1.6   oster 	comp.row = 0;
    581  1.6   oster 	comp.column = component_num;
    582  1.6   oster 	strncpy(comp.component_name, component, sizeof(comp.component_name));
    583  1.6   oster 
    584  1.6   oster 	do_ioctl( fd, RAIDFRAME_REBUILD_IN_PLACE, &comp,
    585  1.6   oster 		  "RAIDFRAME_REBUILD_IN_PLACE");
    586  1.5   oster }
    587  1.5   oster 
    588  1.5   oster 
    589  1.5   oster static void
    590  1.1   oster usage()
    591  1.1   oster {
    592  1.6   oster 	fprintf(stderr, "usage: %s -a component dev\n", __progname);
    593  1.6   oster 	fprintf(stderr, "       %s -B dev\n", __progname);
    594  1.6   oster 	fprintf(stderr, "       %s -c config_file dev\n", __progname);
    595  1.6   oster 	fprintf(stderr, "       %s -C config_file dev\n", __progname);
    596  1.1   oster 	fprintf(stderr, "       %s -f component dev\n", __progname);
    597  1.1   oster 	fprintf(stderr, "       %s -F component dev\n", __progname);
    598  1.6   oster 	fprintf(stderr, "       %s -g component dev\n", __progname);
    599  1.6   oster 	fprintf(stderr, "       %s -i dev\n", __progname);
    600  1.5   oster 	fprintf(stderr, "       %s -I serial_number dev\n", __progname);
    601  1.6   oster 	fprintf(stderr, "       %s -r component dev\n", __progname);
    602  1.6   oster 	fprintf(stderr, "       %s -R component dev\n", __progname);
    603  1.1   oster 	fprintf(stderr, "       %s -s dev\n", __progname);
    604  1.6   oster 	fprintf(stderr, "       %s -S dev\n", __progname);
    605  1.1   oster 	fprintf(stderr, "       %s -u dev\n", __progname);
    606  1.6   oster #if 0
    607  1.6   oster 	fprintf(stderr, "usage: %s %s\n", __progname,
    608  1.6   oster 		"-a | -f | -F | -g | -r | -R component dev");
    609  1.6   oster 	fprintf(stderr, "       %s -B | -i | -s | -S -u dev\n", __progname);
    610  1.6   oster 	fprintf(stderr, "       %s -c | -C config_file dev\n", __progname);
    611  1.6   oster 	fprintf(stderr, "       %s -I serial_number dev\n", __progname);
    612  1.5   oster #endif
    613  1.1   oster 	exit(1);
    614  1.1   oster 	/* NOTREACHED */
    615  1.1   oster }
    616