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: src/sys/dev/vinum/vinumext.h,v 1.25.2.3 2001/05/11 02:11:06 grog Exp $ 38 * $DragonFly: src/sys/dev/raid/vinum/vinumext.h,v 1.5 2005/01/27 02:43:12 joerg Exp $ 39 */ 40 41 /* vinumext.h: external definitions */ 42 43 extern struct _vinum_conf vinum_conf; /* configuration information */ 44 45 #ifdef VINUMDEBUG 46 extern int debug; /* debug flags */ 47 #endif 48 49 /* Physical read and write drive */ 50 #define read_drive(a, b, c, d) driveio (a, b, c, d, B_READ) 51 #define write_drive(a, b, c, d) driveio (a, b, c, d, B_WRITE) 52 53 #define CHECKALLOC(ptr, msg) \ 54 if (ptr == NULL) \ 55 { \ 56 printf (msg); \ 57 longjmp (command_fail, -1); \ 58 } 59 #ifndef _KERNEL 60 struct vnode; 61 struct proc; 62 #endif 63 64 #ifdef _KERNEL 65 int vinum_inactive(int); 66 void free_vinum(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); 114 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, int); 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 *,...); 124 125 /* XXX die die */ 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); 131 132 int vinum_scandisk(char *drivename[], int drives); 133 134 /* I/O */ 135 d_open_t vinumopen; 136 d_close_t vinumclose; 137 d_strategy_t vinumstrategy; 138 d_ioctl_t vinumioctl; 139 d_dump_t vinumdump; 140 d_psize_t vinumsize; 141 142 int vinumstart(struct buf *bp, int reviveok); 143 int launch_requests(struct request *rq, int reviveok); 144 void sdio(struct buf *bp); 145 146 /* XXX Do we need this? */ 147 int vinumpart(dev_t); 148 149 extern jmp_buf command_fail; /* return here if config fails */ 150 extern struct cdevsw vinum_cdevsw; 151 152 #ifdef VINUMDEBUG 153 /* Memory allocation and request tracing */ 154 void vinum_meminfo(caddr_t data); 155 int vinum_mallocinfo(caddr_t data); 156 int vinum_rqinfo(caddr_t data); 157 void LongJmp(jmp_buf, int); 158 #else 159 void longjmp(jmp_buf, int); /* the kernel doesn't define this */ 160 #endif 161 int setjmp(jmp_buf); 162 163 char *basename(char *); 164 void expand_table(void **, int, int); 165 166 struct request; 167 struct rqgroup *allocrqg(struct request *rq, int elements); 168 void deallocrqg(struct rqgroup *rqg); 169 170 /* Device number decoding */ 171 int Volno(dev_t x); 172 int Plexno(dev_t x); 173 int Sdno(dev_t x); 174 175 /* State transitions */ 176 int set_drive_state(int driveno, enum drivestate state, enum setstateflags flags); 177 int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags); 178 enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend); 179 int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags); 180 int set_volume_state(int volumeno, enum volumestate state, enum setstateflags flags); 181 void update_sd_state(int sdno); 182 void forceup(int plexno); 183 void update_plex_state(int plexno); 184 void update_volume_state(int volno); 185 void invalidate_subdisks(struct plex *, enum sdstate); 186 void get_volume_label(char *name, int plexes, u_int64_t size, struct disklabel *lp); 187 int write_volume_label(int); 188 void start_object(struct vinum_ioctl_msg *); 189 void stop_object(struct vinum_ioctl_msg *); 190 void setstate(struct vinum_ioctl_msg *msg); 191 void setstate_by_force(struct vinum_ioctl_msg *msg); 192 void vinum_label(int); 193 int vinum_writedisklabel(struct volume *, struct disklabel *); 194 int initsd(int, int); 195 struct buf *parityrebuild(struct plex *, u_int64_t, int, enum parityop, struct rangelock **, off_t *); 196 enum requeststatus sddownstate(struct request *rq); 197 198 int restart_plex(int plexno); 199 int revive_read(struct sd *sd); 200 int revive_block(int sdno); 201 void parityops(struct vinum_ioctl_msg *); 202 203 /* Auxiliary functions */ 204 enum sdstates sdstatemap(struct plex *plex); 205 enum volplexstate vpstate(struct plex *plex); 206 #endif 207 208 enum keyword get_keyword(char *, struct keywordset *); 209 void listconfig(void); 210 char *drive_state(enum drivestate); 211 char *volume_state(enum volumestate); 212 char *plex_state(enum plexstate); 213 char *plex_org(enum plexorg); 214 char *sd_state(enum sdstate); 215 enum drivestate DriveState(char *text); 216 enum sdstate SdState(char *text); 217 enum plexstate PlexState(char *text); 218 enum volumestate VolState(char *text); 219 struct drive *validdrive(int driveno, struct _ioctl_reply *); 220 struct sd *validsd(int sdno, struct _ioctl_reply *); 221 struct plex *validplex(int plexno, struct _ioctl_reply *); 222 struct volume *validvol(int volno, struct _ioctl_reply *); 223 int tokenize(char *, char *[]); 224 void resetstats(struct vinum_ioctl_msg *msg); 225 226 /* Locking */ 227 #ifdef VINUMDEBUG 228 int lockdrive(struct drive *drive, char *, int); 229 #else 230 int lockdrive(struct drive *drive); 231 #endif 232 void unlockdrive(struct drive *drive); 233 int lockvol(struct volume *vol); 234 void unlockvol(struct volume *vol); 235 int lockplex(struct plex *plex); 236 void unlockplex(struct plex *plex); 237 struct rangelock *lockrange(daddr_t stripe, struct buf *bp, struct plex *plex); 238 int lock_config(void); 239 void unlock_config(void); 240 241 /* D�mon */ 242 243 void vinum_daemon(void); 244 int vinum_finddaemon(void); 245 int vinum_setdaemonopts(int); 246 extern struct daemonq *daemonq; /* daemon's work queue */ 247 extern struct daemonq *dqend; /* and the end of the queue */ 248 249 #undef Free /* defined in some funny net stuff */ 250 #ifdef _KERNEL 251 #ifdef VINUMDEBUG 252 #define Malloc(x) MMalloc ((x), __FILE__, __LINE__) /* show where we came from */ 253 #define Free(x) FFree ((x), __FILE__, __LINE__) /* show where we came from */ 254 caddr_t MMalloc(int size, char *, int); 255 void FFree(void *mem, char *, int); 256 #define LOCKDRIVE(d) lockdrive (d, __FILE__, __LINE__) 257 #else 258 #define Malloc(x) malloc((x), M_DEVBUF, \ 259 mycpu->gd_intr_nesting_level == 0? M_WAITOK: M_INTWAIT) 260 #define Free(x) free((x), M_DEVBUF) 261 #define LOCKDRIVE(d) lockdrive (d) 262 #endif 263 #else 264 #define Malloc(x) malloc ((x)) /* just the size */ 265 #define Free(x) free ((x)) /* just the address */ 266 #endif 267 268 /* Local Variables: */ 269 /* fill-column: 50 */ 270 /* End: */ 271