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 * $Id: vinumext.h,v 1.26 2000/05/16 07:38:08 grog Exp grog $
37 * $FreeBSD$
38 */
39
40 /* vinumext.h: external definitions */
41
42 extern struct _vinum_conf vinum_conf; /* configuration information */
43
44 #ifdef VINUMDEBUG
45 extern int debug; /* debug flags */
46 #endif
47
48 /* Physical read and write drive */
49 #define read_drive(a, b, c, d) driveio (a, b, c, d, B_READ)
50 #define write_drive(a, b, c, d) driveio (a, b, c, d, B_WRITE)
51
52 #define CHECKALLOC(ptr, msg) \
53 if (ptr == NULL) \
54 { \
55 printf (msg); \
56 longjmp (command_fail, -1); \
57 }
58 #ifndef _KERNEL
59 struct vnode;
60 struct proc;
61 #endif
62
63 #ifdef _KERNEL
64 int vinum_inactive(int);
65 void free_vinum(int);
66 int give_sd_to_plex(int plexno, int sdno);
67 void give_sd_to_drive(int sdno);
68 int give_plex_to_volume(int volno, int plexno);
69 struct drive *check_drive(char *);
70 enum drive_label_info read_drive_label(struct drive *, int);
71 int parse_config(char *, struct keywordset *, int);
72 int parse_user_config(char *cptr, struct keywordset *keyset);
73 u_int64_t sizespec(char *spec);
74 int volume_index(struct volume *volume);
75 int plex_index(struct plex *plex);
76 int sd_index(struct sd *sd);
77 int drive_index(struct drive *drive);
78 int my_plex(int volno, int plexno);
79 int my_sd(int plexno, int sdno);
80 int get_empty_drive(void);
81 int find_drive(const char *name, int create);
82 int find_drive_by_dev(const char *devname, int create);
83 int get_empty_sd(void);
84 int find_subdisk(const char *name, int create);
85 void return_drive_space(int driveno, int64_t offset, int length);
86 void free_sd(int sdno);
87 void free_volume(int volno);
88 int get_empty_plex(void);
89 int find_plex(const char *name, int create);
90 void free_plex(int plexno);
91 int get_empty_volume(void);
92 int find_volume(const char *name, int create);
93 void config_subdisk(int);
94 void config_plex(int);
95 void config_volume(int);
96 void config_drive(int);
97 void updateconfig(int);
98 void update_sd_config(int sdno, int kernelstate);
99 void update_plex_config(int plexno, int kernelstate);
100 void update_volume_config(int volno, int kernelstate);
101 void update_config(void);
102 void drive_io_done(struct buf *);
103 void save_config(void);
104 void daemon_save_config(void);
105 void write_config(char *, int);
106 int start_config(int);
107 void finish_config(int);
108 void remove(struct vinum_ioctl_msg *msg);
109 void remove_drive_entry(int driveno, int force);
110 void remove_sd_entry(int sdno, int force, int recurse);
111 void remove_plex_entry(int plexno, int force, int recurse);
112 void remove_volume_entry(int volno, int force, int recurse);
113
114 void checkdiskconfig(char *);
115 int open_drive(struct drive *, struct proc *, int);
116 void close_drive(struct drive *drive);
117 void close_locked_drive(struct drive *drive);
118 int driveio(struct drive *, char *, size_t, off_t, int);
119 int set_drive_parms(struct drive *drive);
120 int init_drive(struct drive *, int);
121 /* void throw_rude_remark (int, struct _ioctl_reply *, char *, ...); XXX */
122 void throw_rude_remark(int, char *,...);
123
124 /* XXX die die */
125 void format_config(char *config, int len);
126 void checkkernel(char *op);
127 void free_drive(struct drive *drive);
128 void down_drive(struct drive *drive);
129 void remove_drive(int driveno);
130
131 int vinum_scandisk(char *drivename[], int drives);
132
133 /* I/O */
134 d_open_t vinumopen;
135 d_close_t vinumclose;
136 d_strategy_t vinumstrategy;
137 d_ioctl_t vinumioctl;
138 d_dump_t vinumdump;
139 d_psize_t vinumsize;
140
141 int vinumstart(struct buf *bp, int reviveok);
142 int launch_requests(struct request *rq, int reviveok);
143 void sdio(struct buf *bp);
144
145 /* XXX Do we need this? */
146 int vinumpart(dev_t);
147
148 extern jmp_buf command_fail; /* return here if config fails */
149
150 #ifdef VINUMDEBUG
151 /* Memory allocation and request tracing */
152 void vinum_meminfo(caddr_t data);
153 int vinum_mallocinfo(caddr_t data);
154 int vinum_rqinfo(caddr_t data);
155 void LongJmp(jmp_buf, int);
156 char *basename(char *);
157 #else
158 void longjmp(jmp_buf, int); /* the kernel doesn't define this */
159 #endif
160 int setjmp(jmp_buf);
161
162 void expand_table(void **, int, int);
163
164 struct request;
165 struct rqgroup *allocrqg(struct request *rq, int elements);
166 void deallocrqg(struct rqgroup *rqg);
167
168 /* Device number decoding */
169 int Volno(dev_t x);
170 int Plexno(dev_t x);
171 int Sdno(dev_t x);
172
173 /* State transitions */
174 int set_drive_state(int driveno, enum drivestate state, enum setstateflags flags);
175 int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags);
176 enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend);
177 int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags);
178 int set_volume_state(int volumeno, enum volumestate state, enum setstateflags flags);
179 void update_sd_state(int sdno);
180 void forceup(int plexno);
181 void update_plex_state(int plexno);
182 void update_volume_state(int volno);
183 void invalidate_subdisks(struct plex *, enum sdstate);
184 void get_volume_label(char *name, int plexes, u_int64_t size, struct disklabel *lp);
185 int write_volume_label(int);
186 void start_object(struct vinum_ioctl_msg *);
187 void stop_object(struct vinum_ioctl_msg *);
188 void setstate(struct vinum_ioctl_msg *msg);
189 void setstate_by_force(struct vinum_ioctl_msg *msg);
190 void vinum_label(int);
191 int vinum_writedisklabel(struct volume *, struct disklabel *);
192 int initsd(int, int);
193 struct buf *parityrebuild(struct plex *, u_int64_t, int, enum parityop, struct rangelock **, off_t *);
194 enum requeststatus sddownstate(struct request *rq);
195
196 int restart_plex(int plexno);
197 int revive_read(struct sd *sd);
198 int revive_block(int sdno);
199 void parityops(struct vinum_ioctl_msg *);
200
201 /* Auxiliary functions */
202 enum sdstates sdstatemap(struct plex *plex);
203 enum volplexstate vpstate(struct plex *plex);
204 #endif
205
206 enum keyword get_keyword(char *, struct keywordset *);
207 void listconfig(void);
208 char *drive_state(enum drivestate);
209 char *volume_state(enum volumestate);
210 char *plex_state(enum plexstate);
211 char *plex_org(enum plexorg);
212 char *sd_state(enum sdstate);
213 enum drivestate DriveState(char *text);
214 enum sdstate SdState(char *text);
215 enum plexstate PlexState(char *text);
216 enum volumestate VolState(char *text);
217 struct drive *validdrive(int driveno, struct _ioctl_reply *);
218 struct sd *validsd(int sdno, struct _ioctl_reply *);
219 struct plex *validplex(int plexno, struct _ioctl_reply *);
220 struct volume *validvol(int volno, struct _ioctl_reply *);
221 int tokenize(char *, char *[]);
222 void resetstats(struct vinum_ioctl_msg *msg);
223
224 /* Locking */
225 #ifdef VINUMDEBUG
226 int lockdrive(struct drive *drive, char *, int);
227 #else
228 int lockdrive(struct drive *drive);
229 #endif
230 void unlockdrive(struct drive *drive);
231 int lockvol(struct volume *vol);
232 void unlockvol(struct volume *vol);
233 int lockplex(struct plex *plex);
234 void unlockplex(struct plex *plex);
235 struct rangelock *lockrange(daddr_t stripe, struct buf *bp, struct plex *plex);
236 int lock_config(void);
237 void unlock_config(void);
238
239 /* Dæmon */
240
241 void vinum_daemon(void);
242 int vinum_finddaemon(void);
243 int vinum_setdaemonopts(int);
244 extern struct daemonq *daemonq; /* daemon's work queue */
245 extern struct daemonq *dqend; /* and the end of the queue */
246
247 #undef Free /* defined in some funny net stuff */
248 #ifdef _KERNEL
249 #ifdef VINUMDEBUG
250 #define Malloc(x) MMalloc ((x), __FILE__, __LINE__) /* show where we came from */
251 #define Free(x) FFree ((x), __FILE__, __LINE__) /* show where we came from */
252 caddr_t MMalloc(int size, char *, int);
253 void FFree(void *mem, char *, int);
254 #define LOCKDRIVE(d) lockdrive (d, __FILE__, __LINE__)
255 #else
256 #define Malloc(x) malloc((x), M_DEVBUF, \
257 intr_nesting_level == 0? M_WAITOK: M_NOWAIT)
258 #define Free(x) free((x), M_DEVBUF)
259 #define LOCKDRIVE(d) lockdrive (d)
260 #endif
261 #else
262 #define Malloc(x) malloc ((x)) /* just the size */
263 #define Free(x) free ((x)) /* just the address */
264 #endif
265
266 /* Local Variables: */
267 /* fill-column: 50 */
268 /* End: */
Cache object: 9b4843618014188d9161d6097c6a311b
|