2 * Copyright (c) 1997, 1998
3 * Nan Yang Computer Services Limited. All rights reserved.
5 * This software is distributed under the so-called ``Berkeley
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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
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.
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.
38 * vinumext.h: external definitions
41 extern struct _vinum_conf vinum_conf; /* configuration information */
44 extern int debug; /* debug flags */
48 * Physical read and write drive
50 #define read_drive(a, b, c, d) driveio (a, b, c, d, BUF_CMD_READ)
51 #define write_drive(a, b, c, d) driveio (a, b, c, d, BUF_CMD_WRITE)
53 #define CHECKALLOC(ptr, msg) \
56 longjmp (command_fail, -1); \
65 int vinum_inactive(int);
67 int give_sd_to_plex(int plexno, int sdno);
68 void give_sd_to_drive(int sdno);
69 int give_plex_to_volume(int volno, int plexno);
70 struct drive *check_drive(char *);
71 enum drive_label_info read_drive_label(struct drive *, int);
72 int parse_config(char *, struct keywordset *, int);
73 int parse_user_config(char *cptr, struct keywordset *keyset);
74 u_int64_t sizespec(char *spec);
75 int volume_index(struct volume *volume);
76 int plex_index(struct plex *plex);
77 int sd_index(struct sd *sd);
78 int drive_index(struct drive *drive);
79 int my_plex(int volno, int plexno);
80 int my_sd(int plexno, int sdno);
81 int get_empty_drive(void);
82 int find_drive(const char *name, int create);
83 int find_drive_by_dev(const char *devname, int create);
84 int get_empty_sd(void);
85 int find_subdisk(const char *name, int create);
86 void return_drive_space(int driveno, int64_t offset, int length);
87 void free_sd(int sdno);
88 void free_volume(int volno);
89 int get_empty_plex(void);
90 int find_plex(const char *name, int create);
91 void free_plex(int plexno);
92 int get_empty_volume(void);
93 int find_volume(const char *name, int create);
94 void config_subdisk(int);
95 void config_plex(int);
96 void config_volume(int);
97 void config_drive(int);
98 void updateconfig(int);
99 void update_sd_config(int sdno, int kernelstate);
100 void update_plex_config(int plexno, int kernelstate);
101 void update_volume_config(int volno, int kernelstate);
102 void update_config(void);
103 void drive_io_done(struct buf *);
104 void save_config(void);
105 void daemon_save_config(void);
106 void write_config(char *, int);
107 int start_config(int);
108 void finish_config(int);
109 void remove(struct vinum_ioctl_msg *msg);
110 void remove_drive_entry(int driveno, int force);
111 void remove_sd_entry(int sdno, int force, int recurse);
112 void remove_plex_entry(int plexno, int force, int recurse);
113 void remove_volume_entry(int volno, int force, int recurse);
115 void checkdiskconfig(char *);
116 int open_drive(struct drive *, struct proc *, int);
117 void close_drive(struct drive *drive);
118 void close_locked_drive(struct drive *drive);
119 int driveio(struct drive *, char *, size_t, off_t, buf_cmd_t);
120 int set_drive_parms(struct drive *drive);
121 int init_drive(struct drive *, int);
122 /* void throw_rude_remark (int, struct _ioctl_reply *, char *, ...); XXX */
123 void throw_rude_remark(int, char *,...) __printflike(2, 3);
126 void format_config(char *config, int len);
127 void checkkernel(char *op);
128 void free_drive(struct drive *drive);
129 void down_drive(struct drive *drive);
130 void remove_drive(int driveno);
132 int vinum_scandisk(char *drivename[], int drives);
136 d_close_t vinumclose;
137 d_strategy_t vinumstrategy;
138 d_ioctl_t vinumioctl;
141 d_kqfilter_t vinumkqfilter;
143 int vinumfilt_rd(struct knote *, long);
144 int vinumfilt_wr(struct knote *, long);
145 void vinumfilt_detach(struct knote *);
147 int vinumstart(cdev_t dev, struct bio *bio, int reviveok);
148 int launch_requests(struct request *rq, int reviveok);
149 void sdio(struct bio *bio);
151 /* XXX Do we need this? */
152 int vinumpart(cdev_t);
154 extern jmp_buf command_fail; /* return here if config fails */
155 extern struct dev_ops vinum_ops;
158 /* Memory allocation and request tracing */
159 void vinum_meminfo(caddr_t data);
160 int vinum_mallocinfo(caddr_t data);
161 int vinum_rqinfo(caddr_t data);
162 void LongJmp(jmp_buf, int);
164 void longjmp(jmp_buf, int); /* the kernel doesn't define this */
168 char *basename(char *);
169 void expand_table(void **, int, int);
172 struct rqgroup *allocrqg(struct request *rq, int elements);
173 void deallocrqg(struct rqgroup *rqg);
175 /* Device number decoding */
177 int Plexno(cdev_t x);
180 /* State transitions */
181 int set_drive_state(int driveno, enum drivestate state, enum setstateflags flags);
182 int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags);
183 enum requeststatus checksdstate(struct sd *sd, struct request *rq, vinum_off_t diskaddr, vinum_off_t diskend);
184 int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags);
185 int set_volume_state(int volumeno, enum volumestate state, enum setstateflags flags);
186 void update_sd_state(int sdno);
187 void forceup(int plexno);
188 void update_plex_state(int plexno);
189 void update_volume_state(int volno);
190 void invalidate_subdisks(struct plex *, enum sdstate);
191 void start_object(struct vinum_ioctl_msg *);
192 void stop_object(struct vinum_ioctl_msg *);
193 void setstate(struct vinum_ioctl_msg *msg);
194 void setstate_by_force(struct vinum_ioctl_msg *msg);
195 void vinum_label(int);
196 int initsd(int, int);
197 struct buf *parityrebuild(struct plex *, vinum_off_t, int, enum parityop, struct rangelock **, off_t *);
198 enum requeststatus sddownstate(struct request *rq);
200 int restart_plex(int plexno);
201 int revive_read(struct sd *sd);
202 int revive_block(int sdno);
203 void parityops(struct vinum_ioctl_msg *);
205 /* Auxiliary functions */
206 enum sdstates sdstatemap(struct plex *plex);
207 enum volplexstate vpstate(struct plex *plex);
210 enum keyword get_keyword(char *, struct keywordset *);
211 void listconfig(void);
212 char *drive_state(enum drivestate);
213 char *volume_state(enum volumestate);
214 char *plex_state(enum plexstate);
215 char *plex_org(enum plexorg);
216 char *sd_state(enum sdstate);
217 enum drivestate DriveState(char *text);
218 enum sdstate SdState(char *text);
219 enum plexstate PlexState(char *text);
220 enum volumestate VolState(char *text);
221 struct drive *validdrive(int driveno, struct _ioctl_reply *);
222 struct sd *validsd(int sdno, struct _ioctl_reply *);
223 struct plex *validplex(int plexno, struct _ioctl_reply *);
224 struct volume *validvol(int volno, struct _ioctl_reply *);
225 int tokenize(char *, char *[]);
226 void resetstats(struct vinum_ioctl_msg *msg);
230 int lockdrive(struct drive *drive, char *, int);
232 int lockdrive(struct drive *drive);
234 void unlockdrive(struct drive *drive);
235 int lockvol(struct volume *vol);
236 void unlockvol(struct volume *vol);
237 int lockplex(struct plex *plex);
238 void unlockplex(struct plex *plex);
239 struct rangelock *lockrange(vinum_off_t stripe, struct buf *bp, struct plex *plex);
240 int lock_config(void);
241 void unlock_config(void);
245 void vinum_daemon(void);
246 int vinum_finddaemon(void);
247 int vinum_setdaemonopts(int);
249 extern struct daemonq *daemonq; /* daemon's work queue */
250 extern struct daemonq *dqend; /* and the end of the queue */
252 #undef Free /* defined in some funny net stuff */
255 #define Malloc(x) MMalloc ((x), __FILE__, __LINE__)
256 #define Free(x) FFree ((x), __FILE__, __LINE__)
257 caddr_t MMalloc(int size, char *, int);
258 void FFree(void *mem, char *, int);
259 #define LOCKDRIVE(d) lockdrive (d, __FILE__, __LINE__)
261 #define Malloc(x) kmalloc((x), M_DEVBUF, \
262 mycpu->gd_intr_nesting_level == 0? M_WAITOK: M_INTWAIT)
263 #define Free(x) kfree((x), M_DEVBUF)
264 #define LOCKDRIVE(d) lockdrive (d)
267 #define Malloc(x) malloc ((x)) /* just the size */
268 #define Free(x) free ((x)) /* just the address */