Home | History | Annotate | Line # | Download | only in raidctl
raidctl.c revision 1.5
      1  1.5   oster /*      $NetBSD: raidctl.c,v 1.5 1999/02/24 00:03:12 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.1   oster static  void rf_fail_disk __P((int, char *, int));
     74  1.1   oster static  void usage __P((void));
     75  1.5   oster static  void get_component_label __P((int, char *));
     76  1.5   oster static  void set_component_label __P((int, char *));
     77  1.5   oster static  void init_component_labels __P((int, int));
     78  1.5   oster static  void add_hot_spare __P((int, char *));
     79  1.1   oster 
     80  1.1   oster int
     81  1.1   oster main(argc,argv)
     82  1.1   oster 	int argc;
     83  1.1   oster 	char *argv[];
     84  1.1   oster {
     85  1.1   oster 	extern char *optarg;
     86  1.1   oster 	extern int optind;
     87  1.1   oster 	int ch;
     88  1.1   oster 	int num_options;
     89  1.1   oster 	unsigned long action;
     90  1.1   oster 	char config_filename[PATH_MAX];
     91  1.1   oster 	char dev_name[PATH_MAX];
     92  1.1   oster 	char name[PATH_MAX];
     93  1.5   oster 	char component[PATH_MAX];
     94  1.1   oster 	int do_recon;
     95  1.1   oster 	int raidID;
     96  1.1   oster 	int rawpart;
     97  1.1   oster 	int recon_percent_done;
     98  1.5   oster 	int serial_number;
     99  1.1   oster 	struct stat st;
    100  1.1   oster 	int fd;
    101  1.5   oster 	int force;
    102  1.1   oster 
    103  1.1   oster 	num_options = 0;
    104  1.1   oster 	action = 0;
    105  1.1   oster 	do_recon = 0;
    106  1.5   oster 	force = 0;
    107  1.1   oster 
    108  1.5   oster #ifdef NOT_YET_BOYS_AND_GIRLS
    109  1.5   oster 	while ((ch = getopt(argc, argv, "a:c:Cf:F:g:I:l:rRsuX:")) != -1)
    110  1.5   oster #endif
    111  1.1   oster 	while ((ch = getopt(argc, argv, "c:Cf:F:rRsu")) != -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.1   oster 		case 'c':
    119  1.1   oster 			strncpy(config_filename,optarg,PATH_MAX);
    120  1.1   oster 			action = RAIDFRAME_CONFIGURE;
    121  1.1   oster 			num_options++;
    122  1.1   oster 			break;
    123  1.1   oster 		case 'C':
    124  1.1   oster 			action = RAIDFRAME_COPYBACK;
    125  1.1   oster 			num_options++;
    126  1.1   oster 			break;
    127  1.1   oster 		case 'f':
    128  1.1   oster 			action = RAIDFRAME_FAIL_DISK;
    129  1.1   oster 			do_recon = 0;
    130  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    131  1.1   oster 			num_options++;
    132  1.1   oster 			break;
    133  1.1   oster 		case 'F':
    134  1.1   oster 			action = RAIDFRAME_FAIL_DISK;
    135  1.1   oster 			do_recon = 1;
    136  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    137  1.5   oster 			num_options++;
    138  1.5   oster 			break;
    139  1.5   oster 		case 'g':
    140  1.5   oster 			action = RAIDFRAME_GET_COMPONENT_LABEL;
    141  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    142  1.5   oster 			num_options++;
    143  1.5   oster 			break;
    144  1.5   oster 		case 'I':
    145  1.5   oster 			action = RAIDFRAME_INIT_LABELS;
    146  1.5   oster 			serial_number = atoi(optarg);
    147  1.5   oster 			num_options++;
    148  1.5   oster 			break;
    149  1.5   oster 		case 'l':
    150  1.5   oster 			action = RAIDFRAME_SET_COMPONENT_LABEL;
    151  1.5   oster 			strncpy(component, optarg, PATH_MAX);
    152  1.1   oster 			num_options++;
    153  1.1   oster 			break;
    154  1.1   oster 		case 'r':
    155  1.1   oster 			action = RAIDFRAME_REWRITEPARITY;
    156  1.1   oster 			num_options++;
    157  1.1   oster 			break;
    158  1.1   oster 		case 'R':
    159  1.1   oster 			action = RAIDFRAME_CHECKRECON;
    160  1.1   oster 			num_options++;
    161  1.1   oster 			break;
    162  1.1   oster 		case 's':
    163  1.1   oster 			action = RAIDFRAME_GET_INFO;
    164  1.1   oster 			num_options++;
    165  1.1   oster 			break;
    166  1.1   oster 		case 'u':
    167  1.1   oster 			action = RAIDFRAME_SHUTDOWN;
    168  1.1   oster 			num_options++;
    169  1.1   oster 			break;
    170  1.5   oster 		case 'X':
    171  1.5   oster 			strncpy(config_filename,optarg,PATH_MAX);
    172  1.5   oster 			action = RAIDFRAME_CONFIGURE;
    173  1.5   oster 			force = 1;
    174  1.5   oster 			num_options++;
    175  1.5   oster 			break;
    176  1.1   oster 		default:
    177  1.1   oster 			usage();
    178  1.1   oster 		}
    179  1.1   oster 	argc -= optind;
    180  1.1   oster 	argv += optind;
    181  1.1   oster 
    182  1.1   oster 	if ((num_options > 1) || (argc == NULL))
    183  1.1   oster 		usage();
    184  1.1   oster 
    185  1.1   oster 	strncpy(name,argv[0],PATH_MAX);
    186  1.1   oster 
    187  1.1   oster 	if ((name[0] == '/') || (name[0] == '.')) {
    188  1.1   oster 		/* they've (apparently) given a full path... */
    189  1.1   oster 		strncpy(dev_name, name, PATH_MAX);
    190  1.1   oster 	} else {
    191  1.1   oster 		if (isdigit(name[strlen(name)-1])) {
    192  1.1   oster 			rawpart = getrawpartition();
    193  1.1   oster 			snprintf(dev_name,PATH_MAX,"/dev/%s%c",name,
    194  1.1   oster 				 'a'+rawpart);
    195  1.1   oster 		} else {
    196  1.1   oster 			snprintf(dev_name,PATH_MAX,"/dev/%s",name);
    197  1.1   oster 		}
    198  1.1   oster 	}
    199  1.1   oster 
    200  1.1   oster 	if (stat(dev_name, &st) != 0) {
    201  1.1   oster 		fprintf(stderr,"%s: stat failure on: %s\n",
    202  1.1   oster 			__progname,dev_name);
    203  1.1   oster 		return (errno);
    204  1.1   oster 	}
    205  1.1   oster 	if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
    206  1.1   oster 		fprintf(stderr,"%s: invalid device: %s\n",
    207  1.1   oster 			__progname,dev_name);
    208  1.1   oster 		return (EINVAL);
    209  1.1   oster 	}
    210  1.1   oster 
    211  1.1   oster 	raidID = RF_DEV2RAIDID(st.st_rdev);
    212  1.1   oster 
    213  1.1   oster 	if ((fd = open( dev_name, O_RDWR, 0640)) < 0) {
    214  1.1   oster 		fprintf(stderr, "%s: unable to open device file: %s\n",
    215  1.1   oster 			__progname, dev_name);
    216  1.1   oster 		exit(1);
    217  1.1   oster 	}
    218  1.1   oster 
    219  1.1   oster 
    220  1.1   oster 	switch(action) {
    221  1.5   oster 	case RAIDFRAME_ADD_HOT_SPARE:
    222  1.5   oster 		add_hot_spare(fd,component);
    223  1.5   oster 		break;
    224  1.1   oster 	case RAIDFRAME_CONFIGURE:
    225  1.5   oster 		rf_configure(fd, config_filename,force);
    226  1.1   oster 		break;
    227  1.1   oster 	case RAIDFRAME_COPYBACK:
    228  1.1   oster 		printf("Copyback.\n");
    229  1.1   oster 		do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
    230  1.1   oster 		break;
    231  1.1   oster 	case RAIDFRAME_FAIL_DISK:
    232  1.5   oster 		rf_fail_disk(fd,component,do_recon);
    233  1.5   oster 		break;
    234  1.5   oster 	case RAIDFRAME_SET_COMPONENT_LABEL:
    235  1.5   oster 		set_component_label(fd,component);
    236  1.5   oster 		break;
    237  1.5   oster 	case RAIDFRAME_GET_COMPONENT_LABEL:
    238  1.5   oster 		get_component_label(fd,component);
    239  1.5   oster 		break;
    240  1.5   oster 	case RAIDFRAME_INIT_LABELS:
    241  1.5   oster 		init_component_labels(fd,serial_number);
    242  1.1   oster 		break;
    243  1.1   oster 	case RAIDFRAME_REWRITEPARITY:
    244  1.1   oster 		printf("Initiating re-write of parity\n");
    245  1.1   oster 		do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
    246  1.1   oster 			 "RAIDFRAME_REWRITEPARITY");
    247  1.1   oster 		break;
    248  1.1   oster 	case RAIDFRAME_CHECKRECON:
    249  1.1   oster 		do_ioctl(fd, RAIDFRAME_CHECKRECON, &recon_percent_done,
    250  1.1   oster 			 "RAIDFRAME_CHECKRECON");
    251  1.1   oster 		printf("Reconstruction is %d%% complete.\n",
    252  1.1   oster 		       recon_percent_done);
    253  1.1   oster 		break;
    254  1.1   oster 	case RAIDFRAME_GET_INFO:
    255  1.1   oster 		rf_get_device_status(fd);
    256  1.1   oster 		break;
    257  1.1   oster 	case RAIDFRAME_SHUTDOWN:
    258  1.1   oster 		do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
    259  1.1   oster 		break;
    260  1.1   oster 	default:
    261  1.1   oster 		break;
    262  1.1   oster 	}
    263  1.1   oster 
    264  1.1   oster 	close(fd);
    265  1.1   oster 	exit(0);
    266  1.1   oster }
    267  1.1   oster 
    268  1.1   oster static void
    269  1.1   oster do_ioctl(fd, command, arg, ioctl_name)
    270  1.1   oster 	int fd;
    271  1.1   oster 	unsigned long command;
    272  1.1   oster 	void *arg;
    273  1.1   oster 	char *ioctl_name;
    274  1.1   oster {
    275  1.1   oster 	if (ioctl(fd, command, arg) < 0) {
    276  1.1   oster 		warn("ioctl (%s) failed", ioctl_name);
    277  1.1   oster 		exit(1);
    278  1.1   oster 	}
    279  1.1   oster }
    280  1.1   oster 
    281  1.1   oster 
    282  1.1   oster static void
    283  1.5   oster rf_configure(fd,config_file,force)
    284  1.1   oster 	int fd;
    285  1.1   oster 	char *config_file;
    286  1.5   oster 	int force;
    287  1.1   oster {
    288  1.1   oster 	void *generic;
    289  1.1   oster 	RF_Config_t cfg;
    290  1.1   oster 
    291  1.1   oster 	if (rf_MakeConfig( config_file, &cfg ) < 0) {
    292  1.1   oster 		fprintf(stderr,"%s: unable to create RAIDframe %s\n",
    293  1.1   oster 			__progname, "configuration structure\n");
    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 	   Note the extra level of redirection needed here, since
    300  1.1   oster 	   what we really want to pass in is a pointer to the pointer to
    301  1.1   oster 	   the configuration structure.
    302  1.1   oster 
    303  1.1   oster 	 */
    304  1.1   oster 
    305  1.1   oster 	generic = (void *) &cfg;
    306  1.1   oster 	do_ioctl(fd,RAIDFRAME_CONFIGURE,&generic,"RAIDFRAME_CONFIGURE");
    307  1.5   oster 
    308  1.1   oster }
    309  1.1   oster 
    310  1.1   oster static char *
    311  1.1   oster device_status(status)
    312  1.1   oster 	RF_DiskStatus_t status;
    313  1.1   oster {
    314  1.1   oster 	static char status_string[256];
    315  1.1   oster 
    316  1.1   oster 	switch (status) {
    317  1.1   oster 	case rf_ds_optimal:
    318  1.1   oster 		strcpy(status_string,"optimal");
    319  1.1   oster 		break;
    320  1.1   oster 	case rf_ds_failed:
    321  1.1   oster 		strcpy(status_string,"failed");
    322  1.1   oster 		break;
    323  1.1   oster 	case rf_ds_reconstructing:
    324  1.1   oster 		strcpy(status_string,"reconstructing");
    325  1.1   oster 		break;
    326  1.1   oster 	case rf_ds_dist_spared:
    327  1.1   oster 		strcpy(status_string,"dist_spared");
    328  1.1   oster 		break;
    329  1.1   oster 	case rf_ds_spared:
    330  1.1   oster 		strcpy(status_string,"spared");
    331  1.1   oster 		break;
    332  1.1   oster 	case rf_ds_spare:
    333  1.1   oster 		strcpy(status_string,"spare");
    334  1.1   oster 		break;
    335  1.1   oster 	case rf_ds_used_spare:
    336  1.1   oster 		strcpy(status_string,"used_spare");
    337  1.1   oster 		break;
    338  1.1   oster 	default:
    339  1.1   oster 		strcpy(status_string,"UNKNOWN");
    340  1.1   oster 		break;
    341  1.1   oster 	}
    342  1.1   oster 	return(status_string);
    343  1.1   oster }
    344  1.1   oster 
    345  1.1   oster static void
    346  1.1   oster rf_get_device_status(fd)
    347  1.1   oster 	int fd;
    348  1.1   oster {
    349  1.1   oster 	RF_DeviceConfig_t device_config;
    350  1.1   oster 	void *cfg_ptr;
    351  1.1   oster 	int i;
    352  1.1   oster 
    353  1.1   oster 	cfg_ptr = &device_config;
    354  1.1   oster 
    355  1.1   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr, "RAIDFRAME_GET_INFO");
    356  1.1   oster 
    357  1.1   oster 	printf("Components:\n");
    358  1.1   oster 	for(i=0; i < device_config.ndevs; i++) {
    359  1.1   oster 		printf("%20s: %s\n", device_config.devs[i].devname,
    360  1.1   oster 		       device_status(device_config.devs[i].status));
    361  1.1   oster 	}
    362  1.1   oster 	if (device_config.nspares > 0) {
    363  1.1   oster 		printf("Spares:\n");
    364  1.1   oster 		for(i=0; i < device_config.nspares; i++) {
    365  1.5   oster 			printf("%20s: %s\n",
    366  1.1   oster 			       device_config.spares[i].devname,
    367  1.1   oster 			       device_status(device_config.spares[i].status));
    368  1.1   oster 		}
    369  1.1   oster 	} else {
    370  1.1   oster 		printf("No spares.\n");
    371  1.1   oster 	}
    372  1.1   oster 
    373  1.1   oster }
    374  1.1   oster 
    375  1.1   oster static void
    376  1.1   oster rf_fail_disk(fd, component_to_fail, do_recon)
    377  1.1   oster 	int fd;
    378  1.1   oster 	char *component_to_fail;
    379  1.1   oster 	int do_recon;
    380  1.1   oster {
    381  1.1   oster 	struct rf_recon_req recon_request;
    382  1.1   oster 	RF_DeviceConfig_t device_config;
    383  1.1   oster 	void *cfg_ptr;
    384  1.1   oster 	int i;
    385  1.1   oster 	int found;
    386  1.1   oster 	int component_num;
    387  1.1   oster 
    388  1.1   oster 	component_num = -1;
    389  1.1   oster 
    390  1.1   oster 	/* Assuming a full path spec... */
    391  1.1   oster 	cfg_ptr = &device_config;
    392  1.1   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
    393  1.1   oster 		 "RAIDFRAME_GET_INFO");
    394  1.1   oster 	found = 0;
    395  1.1   oster 	for(i=0; i < device_config.ndevs; i++) {
    396  1.1   oster 		if (strncmp(component_to_fail,
    397  1.1   oster 			    device_config.devs[i].devname,
    398  1.1   oster 			    PATH_MAX)==0) {
    399  1.1   oster 			found = 1;
    400  1.1   oster 			component_num = i;
    401  1.1   oster 		}
    402  1.1   oster 	}
    403  1.1   oster 	if (!found) {
    404  1.1   oster 		fprintf(stderr,"%s: %s is not a component %s",
    405  1.1   oster 			__progname, component_to_fail,
    406  1.1   oster 			"of this device\n");
    407  1.1   oster 		exit(1);
    408  1.1   oster 	}
    409  1.1   oster 
    410  1.1   oster 	recon_request.row = component_num / device_config.cols;
    411  1.1   oster 	recon_request.col = component_num % device_config.cols;
    412  1.1   oster 	if (do_recon) {
    413  1.1   oster 		recon_request.flags = RF_FDFLAGS_RECON;
    414  1.1   oster 	} else {
    415  1.1   oster 		recon_request.flags = RF_FDFLAGS_NONE;
    416  1.1   oster 	}
    417  1.1   oster 	do_ioctl(fd, RAIDFRAME_FAIL_DISK, &recon_request,
    418  1.1   oster 		 "RAIDFRAME_FAIL_DISK");
    419  1.1   oster 
    420  1.1   oster }
    421  1.1   oster 
    422  1.1   oster static void
    423  1.5   oster get_component_label(fd, component)
    424  1.5   oster 	int fd;
    425  1.5   oster 	char *component;
    426  1.5   oster {
    427  1.5   oster 	RF_ComponentLabel_t component_label;
    428  1.5   oster 	RF_DeviceConfig_t device_config;
    429  1.5   oster 	void *cfg_ptr;
    430  1.5   oster 	void *label_ptr;
    431  1.5   oster 	int i;
    432  1.5   oster 	int found;
    433  1.5   oster 	int component_num;
    434  1.5   oster 
    435  1.5   oster 	component_num = -1;
    436  1.5   oster 
    437  1.5   oster 	/* Assuming a full path spec... */
    438  1.5   oster 	cfg_ptr = &device_config;
    439  1.5   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
    440  1.5   oster 		 "RAIDFRAME_GET_INFO");
    441  1.5   oster 	found = 0;
    442  1.5   oster 	for(i=0; i < device_config.ndevs; i++) {
    443  1.5   oster 		if (strncmp(component, device_config.devs[i].devname,
    444  1.5   oster 			    PATH_MAX)==0) {
    445  1.5   oster 			found = 1;
    446  1.5   oster 			component_num = i;
    447  1.5   oster 		}
    448  1.5   oster 	}
    449  1.5   oster 	if (!found) {
    450  1.5   oster 		fprintf(stderr,"%s: %s is not a component %s",
    451  1.5   oster 			__progname, component, "of this device\n");
    452  1.5   oster 		exit(1);
    453  1.5   oster 	}
    454  1.5   oster 
    455  1.5   oster 	memset( &component_label, 0, sizeof(RF_ComponentLabel_t));
    456  1.5   oster 	component_label.row = component_num / device_config.cols;
    457  1.5   oster 	component_label.column = component_num % device_config.cols;
    458  1.5   oster 
    459  1.5   oster 	label_ptr = &component_label;
    460  1.5   oster 	do_ioctl( fd, RAIDFRAME_GET_COMPONENT_LABEL, &label_ptr,
    461  1.5   oster 		  "RAIDFRAME_GET_COMPONENT_LABEL");
    462  1.5   oster 
    463  1.5   oster 	printf("Component label for %s:\n",component);
    464  1.5   oster 	printf("Version: %d\n",component_label.version);
    465  1.5   oster 	printf("Serial Number: %d\n",component_label.serial_number);
    466  1.5   oster 	printf("Mod counter: %d\n",component_label.mod_counter);
    467  1.5   oster 	printf("Row: %d\n", component_label.row);
    468  1.5   oster 	printf("Column: %d\n", component_label.column);
    469  1.5   oster 	printf("Num Rows: %d\n", component_label.num_rows);
    470  1.5   oster 	printf("Num Columns: %d\n", component_label.num_columns);
    471  1.5   oster 	printf("Clean: %d\n", component_label.clean);
    472  1.5   oster 	printf("Status: %s\n", device_status(component_label.status));
    473  1.5   oster 
    474  1.5   oster }
    475  1.5   oster 
    476  1.5   oster static void
    477  1.5   oster set_component_label(fd, component)
    478  1.5   oster 	int fd;
    479  1.5   oster 	char *component;
    480  1.5   oster {
    481  1.5   oster 	RF_ComponentLabel_t component_label;
    482  1.5   oster 	RF_DeviceConfig_t device_config;
    483  1.5   oster 	void *cfg_ptr;
    484  1.5   oster 	int i;
    485  1.5   oster 	int found;
    486  1.5   oster 	int component_num;
    487  1.5   oster 
    488  1.5   oster 	component_num = -1;
    489  1.5   oster 
    490  1.5   oster 	/* Assuming a full path spec... */
    491  1.5   oster 	cfg_ptr = &device_config;
    492  1.5   oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
    493  1.5   oster 		 "RAIDFRAME_GET_INFO");
    494  1.5   oster 	found = 0;
    495  1.5   oster 	for(i=0; i < device_config.ndevs; i++) {
    496  1.5   oster 		if (strncmp(component, device_config.devs[i].devname,
    497  1.5   oster 			    PATH_MAX)==0) {
    498  1.5   oster 			found = 1;
    499  1.5   oster 			component_num = i;
    500  1.5   oster 		}
    501  1.5   oster 	}
    502  1.5   oster 	if (!found) {
    503  1.5   oster 		fprintf(stderr,"%s: %s is not a component %s",
    504  1.5   oster 			__progname, component, "of this device\n");
    505  1.5   oster 		exit(1);
    506  1.5   oster 	}
    507  1.5   oster 
    508  1.5   oster 	component_label.version = 1;
    509  1.5   oster 	component_label.serial_number = 123456;
    510  1.5   oster 	component_label.mod_counter = 0;
    511  1.5   oster 	component_label.row = component_num / device_config.cols;
    512  1.5   oster 	component_label.column = component_num % device_config.cols;
    513  1.5   oster 	component_label.num_rows = 0;
    514  1.5   oster 	component_label.num_columns = 5;
    515  1.5   oster 	component_label.clean = 0;
    516  1.5   oster 	component_label.status = 1;
    517  1.5   oster 
    518  1.5   oster 	do_ioctl( fd, RAIDFRAME_SET_COMPONENT_LABEL, &component_label,
    519  1.5   oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    520  1.5   oster 
    521  1.5   oster }
    522  1.5   oster 
    523  1.5   oster 
    524  1.5   oster static void
    525  1.5   oster init_component_labels(fd, serial_number)
    526  1.5   oster 	int fd;
    527  1.5   oster 	int serial_number;
    528  1.5   oster {
    529  1.5   oster 
    530  1.5   oster 	RF_ComponentLabel_t component_label;
    531  1.5   oster 
    532  1.5   oster 	component_label.version = 0;
    533  1.5   oster 	component_label.serial_number = serial_number;
    534  1.5   oster 	component_label.mod_counter = 0;
    535  1.5   oster 	component_label.row = 0;
    536  1.5   oster 	component_label.column = 0;
    537  1.5   oster 	component_label.num_rows = 0;
    538  1.5   oster 	component_label.num_columns = 0;
    539  1.5   oster 	component_label.clean = 0;
    540  1.5   oster 	component_label.status = 0;
    541  1.5   oster 
    542  1.5   oster 	do_ioctl( fd, RAIDFRAME_INIT_LABELS, &component_label,
    543  1.5   oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    544  1.5   oster 
    545  1.5   oster 
    546  1.5   oster }
    547  1.5   oster 
    548  1.5   oster static void
    549  1.5   oster add_hot_spare(fd, component)
    550  1.5   oster 	int fd;
    551  1.5   oster 	char *component;
    552  1.5   oster {
    553  1.5   oster 	RF_HotSpare_t hot_spare;
    554  1.5   oster 
    555  1.5   oster 	hot_spare.spare_number = 0;
    556  1.5   oster 	strncpy(hot_spare.spare_name, component, sizeof(hot_spare.spare_name));
    557  1.5   oster 
    558  1.5   oster 	do_ioctl( fd, RAIDFRAME_ADD_HOT_SPARE, &hot_spare,
    559  1.5   oster 		  "RAIDFRAME_ADD_HOT_SPARE");
    560  1.5   oster 
    561  1.5   oster }
    562  1.5   oster 
    563  1.5   oster 
    564  1.5   oster static void
    565  1.1   oster usage()
    566  1.1   oster {
    567  1.1   oster 	fprintf(stderr, "usage: %s -c config_file dev\n", __progname);
    568  1.1   oster 	fprintf(stderr, "       %s -C dev\n", __progname);
    569  1.1   oster 	fprintf(stderr, "       %s -f component dev\n", __progname);
    570  1.1   oster 	fprintf(stderr, "       %s -F component dev\n", __progname);
    571  1.5   oster #ifdef NOT_YET_BOYS_AND_GIRLS
    572  1.5   oster 	fprintf(stderr, "       %s -I serial_number dev\n", __progname);
    573  1.5   oster #endif
    574  1.1   oster 	fprintf(stderr, "       %s -r dev\n", __progname);
    575  1.1   oster 	fprintf(stderr, "       %s -R dev\n", __progname);
    576  1.1   oster 	fprintf(stderr, "       %s -s dev\n", __progname);
    577  1.5   oster #ifdef NOT_YET_BOYS_AND_GIRLS
    578  1.1   oster 	fprintf(stderr, "       %s -u dev\n", __progname);
    579  1.5   oster #endif
    580  1.1   oster 	exit(1);
    581  1.1   oster 	/* NOTREACHED */
    582  1.1   oster }
    583