Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sbin / vinum / vext.h
1 /*-
2  * Copyright (c) 1997, 1998
3  *      Nan Yang Computer Services Limited.  All rights reserved.
4  *
5  *  This software is distributed under the so-called ``Berkeley
6  *  License'':
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Nan Yang Computer
19  *      Services Limited.
20  * 4. Neither the name of the Company nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * This software is provided ``as is'', and any express or implied
25  * warranties, including, but not limited to, the implied warranties of
26  * merchantability and fitness for a particular purpose are disclaimed.
27  * In no event shall the company or contributors be liable for any
28  * direct, indirect, incidental, special, exemplary, or consequential
29  * damages (including, but not limited to, procurement of substitute
30  * goods or services; loss of use, data, or profits; or business
31  * interruption) however caused and on any theory of liability, whether
32  * in contract, strict liability, or tort (including negligence or
33  * otherwise) arising in any way out of the use of this software, even if
34  * advised of the possibility of such damage.
35  */
36
37 /*
38  * $Id: vext.h,v 1.17 2000/05/07 04:17:12 grog Exp grog $
39  * $FreeBSD: src/sbin/vinum/vext.h,v 1.16.2.2 2000/06/08 01:53:16 grog Exp $
40  */
41
42 #define MAXARGS 64                                          /* maximum number of args on a line */
43 #define PLEXINITSIZE 65536                                  /* init in this size chunks */
44 #define MAXPLEXINITSIZE 65536                               /* max chunk size to use for init */
45 #define MAXDATETEXT 128                                     /* date text in history (far too much) */
46
47 enum {
48     KILOBYTE = 1024,
49     MEGABYTE = 1048576,
50     GIGABYTE = 1073741824
51 };
52
53 #define VINUMMOD "vinum"
54
55 #define DEFAULT_HISTORYFILE "/var/log/vinum_history"        /* default name for history stuff */
56
57 /* Prototype declarations */
58 void parseline(int c, char *args[]);                        /* parse a line with c parameters at args */
59 void checkentry(int index);
60 int haveargs(int);                                          /* check arg, error message if not valid */
61 void setsigs();
62 void catchsig(int ignore);
63 void vinum_create(int argc, char *argv[], char *arg0[]);
64 void vinum_read(int argc, char *argv[], char *arg0[]);
65 void vinum_modify(int argc, char *argv[], char *arg0[]);
66 void vinum_volume(int argc, char *argv[], char *arg0[]);
67 void vinum_plex(int argc, char *argv[], char *arg0[]);
68 void vinum_sd(int argc, char *argv[], char *arg0[]);
69 void vinum_drive(int argc, char *argv[], char *arg0[]);
70 void vinum_list(int argc, char *argv[], char *arg0[]);
71 void vinum_info(int argc, char *argv[], char *arg0[]);
72 void vinum_set(int argc, char *argv[], char *arg0[]);
73 void vinum_rm(int argc, char *argv[], char *arg0[]);
74 void vinum_mv(int argc, char *argv[], char *arg0[]);
75 void vinum_init(int argc, char *argv[], char *arg0[]);
76 void initvol(int volno);
77 void initplex(int plexno, char *name);
78 void initsd(int sdno, int dowait);
79 void vinum_resetconfig(int argc, char *argv[], char *arg0[]);
80 void vinum_start(int argc, char *argv[], char *arg0[]);
81 void continue_revive(int plexno);
82 void vinum_stop(int argc, char *argv[], char *arg0[]);
83 void vinum_makedev(int argc, char *argv[], char *arg0[]);
84 void vinum_help(int argc, char *argv[], char *arg0[]);
85 void vinum_quit(int argc, char *argv[], char *arg0[]);
86 void vinum_setdaemon(int argc, char *argv[], char *arg0[]);
87 void vinum_replace(int argc, char *argv[], char *arg0[]);
88 void vinum_readpol(int argc, char *argv[], char *arg0[]);
89 void reset_volume_stats(int volno, int recurse);
90 void reset_plex_stats(int plexno, int recurse);
91 void reset_sd_stats(int sdno, int recurse);
92 void reset_drive_stats(int driveno);
93 void vinum_resetstats(int argc, char *argv[], char *arg0[]);
94 void vinum_attach(int argc, char *argv[], char *argv0[]);
95 void vinum_detach(int argc, char *argv[], char *argv0[]);
96 void vinum_rename(int argc, char *argv[], char *argv0[]);
97 void vinum_rename_2(char *, char *);
98 void vinum_replace(int argc, char *argv[], char *argv0[]);
99 void vinum_printconfig(int argc, char *argv[], char *argv0[]);
100 void printconfig(FILE * of, char *comment);
101 void vinum_saveconfig(int argc, char *argv[], char *argv0[]);
102 int checkupdates();
103 void genvolname();
104 struct drive *create_drive(char *devicename);
105 void vinum_concat(int argc, char *argv[], char *argv0[]);
106 void vinum_stripe(int argc, char *argv[], char *argv0[]);
107 void vinum_raid4(int argc, char *argv[], char *argv0[]);
108 void vinum_raid5(int argc, char *argv[], char *argv0[]);
109 void vinum_mirror(int argc, char *argv[], char *argv0[]);
110 void vinum_label(int argc, char *argv[], char *arg0[]);
111 void vinum_ld(int argc, char *argv[], char *arg0[]);
112 void vinum_ls(int argc, char *argv[], char *arg0[]);
113 void vinum_lp(int argc, char *argv[], char *arg0[]);
114 void vinum_lv(int argc, char *argv[], char *arg0[]);
115 void vinum_setstate(int argc, char *argv[], char *argv0[]);
116 void vinum_checkparity(int argc, char *argv[], char *argv0[]);
117 void vinum_rebuildparity(int argc, char *argv[], char *argv0[]);
118 void parityops(int argc, char *argv[], enum parityop op);
119 void start_daemon(void);
120 #ifdef VINUMDEBUG
121 void vinum_debug(int argc, char *argv[], char *arg0[]);
122 #endif
123 struct drive *find_drive_by_devname(char *name);
124 void make_devices(void);
125 void make_vol_dev(int, int);
126 void make_plex_dev(int, int);
127 void make_sd_dev(int);
128 void list_defective_objects();
129 void vinum_dumpconfig(int argc, char *argv[], char *argv0[]);
130 void dumpconfig(char *part);
131 int check_drive(char *devicename);
132 void get_drive_info(struct drive *drive, int index);
133 void get_sd_info(struct sd *sd, int index);
134 void get_plex_sd_info(struct sd *sd, int plexno, int sdno);
135 void get_plex_info(struct plex *plex, int index);
136 void get_volume_info(struct volume *volume, int index);
137 struct drive *find_drive_by_devname(char *name);
138 int find_object(const char *name, enum objecttype *type);
139 char *lltoa(int64_t l, char *s);
140 void vinum_ldi(int, int);
141 void vinum_lvi(int, int);
142 void vinum_lpi(int, int);
143 void vinum_lsi(int, int);
144 int vinum_li(int object, enum objecttype type);
145 char *roughlength(int64_t bytes, int);
146 u_int64_t sizespec(char *spec);
147
148 void timestamp();
149
150 extern int force;                                           /* set to 1 to force some dangerous ops */
151 extern int interval;                                        /* interval in ms between init/revive */
152 extern int vflag;                                           /* set verbose operation or verify */
153 extern int Verbose;                                         /* very verbose operation */
154 extern int recurse;                                         /* set recursion */
155 extern int sflag;                                           /* show statistics */
156 extern int SSize;                                           /* sector size for revive */
157 extern int dowait;                                          /* wait for children to exit */
158 extern char *objectname;                                    /* name for some functions */
159
160 extern FILE *history;                                       /* history file */
161
162 /* Structures to read kernel data into */
163 extern struct _vinum_conf vinum_conf;                       /* configuration information */
164
165 extern struct volume vol;
166 extern struct plex plex;
167 extern struct sd sd;
168 extern struct drive drive;
169
170 extern jmp_buf command_fail;                                /* return on a failed command */
171 extern int superdev;                                        /* vinum super device */
172
173 extern int line;                                            /* stdin line number for error messages */
174 extern int file_line;                                       /* and line in input file (yes, this is tacky) */
175
176 extern char buffer[];                                       /* buffer to read in to */
177
178 #define min(a, b) a < b? a: b