diff --git a/lkm/vinum/config.c b/lkm/vinum/config.c index fd31c5e07c46..4875eb6a7378 100644 --- a/lkm/vinum/config.c +++ b/lkm/vinum/config.c @@ -1,1712 +1,1713 @@ /* To do: * Don't store drive configuration on the config DB: read each drive's header * to decide where it is. * * Accept any old crap in the config_ functions, and complain when * we try to bring it up. * * When trying to bring volumes up, check that the complete address range * is covered. */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: config.c,v 1.17 1998/08/14 04:49:26 grog Exp grog $ + * $Id: config.c,v 1.19 1998/10/05 02:48:15 grog Exp grog $ */ #define STATIC /* nothing while we're testing XXX */ #define REALLYKERNEL #include "vinumhdr.h" extern jmp_buf command_fail; /* return on a failed command */ #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ void longjmp(jmp_buf, int); #endif #define MAXTOKEN 64 /* maximum number of tokens in a line */ /* We can afford the luxury of global variables here, * since start_config ensures that these functions * are single-threaded. */ /* These are indices in vinum_conf of the last-mentioned of each kind of object */ static int current_drive = -1; /* note the last drive we mention, for * some defaults */ static int current_plex = -1; /* and the same for the last plex */ static int current_volume = -1; /* and the last volme */ static struct _ioctl_reply *ioctl_reply; /* struct to return via ioctl */ /* These values are used by most of these routines, so set them as globals */ static char *token[MAXTOKEN]; /* pointers to individual tokens */ static int tokens; /* number of tokens */ #define TOCONS 0x01 #define TOTTY 0x02 #define TOLOG 0x04 struct putchar_arg { int flags; struct tty *tty; }; #define MSG_MAX 1024 /* maximum length of a formatted message */ /* Format an error message and return to the user in the reply. * CARE: This routine is designed to be called only from the * configuration routines, so it assumes it's the owner of * the configuration lock, and unlocks it on exit */ void throw_rude_remark(int error, char *msg,...) { BROKEN_GDB; int retval; va_list ap; char *text; static int finishing; /* don't recurse */ int was_finishing; va_start(ap, msg); if ((ioctl_reply != NULL) /* we're called from the user */ &&(!(vinum_conf.flags & VF_KERNELOP))) { /* and we're not doing kernel things: return msg */ /* XXX We can't just format to ioctl_reply, since it * may contain our input parameters */ text = Malloc(MSG_MAX); if (text == NULL) { printf("vinum: can't allocate error message buffer"); printf("vinum: "); vprintf(msg, ap); /* print to the console */ printf("\n"); } else { retval = kvprintf(msg, NULL, (void *) text, 10, ap); text[retval] = '\0'; /* delimit */ strcpy(ioctl_reply->msg, text); ioctl_reply->error = error; /* first byte is the error number */ Free(text); } } else { printf("vinum: "); vprintf(msg, ap); /* print to the console */ printf("\n"); } va_end(ap); if (vinum_conf.flags & VF_READING_CONFIG) /* go through to the bitter end, */ return; /* We have a problem here: we want to unlock the * configuration, which implies tidying up, but * if we find an error while tidying up, we could * recurse for ever. Use this kludge to only try * once */ was_finishing = finishing; finishing = 1; finish_config(was_finishing); /* unlock anything we may be holding */ finishing = was_finishing; longjmp(command_fail, error); } /* Function declarations */ int atoi(char *); /* no atoi in the kernel */ /* Minimal version of atoi */ int atoi(char *s) { /* no atoi in the kernel */ BROKEN_GDB; int r = 0; int sign = 1; while (((*s >= '0') && (*s <= '9')) || (*s == '-')) { if (*s == '-') sign = -sign; else r = r * 10 + (*s - '0'); } return r; } /* Find index of volume in vinum_conf. Return the index * if found, or -1 if not */ int volume_index(struct volume *vol) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.volumes_used; i++) if (&VOL[i] == vol) return i; return -1; } /* Find index of plex in vinum_conf. Return the index * if found, or -1 if not */ int plex_index(struct plex *plex) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.plexes_used; i++) if (&PLEX[i] == plex) return i; return -1; } /* Find index of subdisk in vinum_conf. Return the index * if found, or -1 if not */ int sd_index(struct sd *sd) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.subdisks_used; i++) if (&SD[i] == sd) return i; return -1; } /* Find index of drive in vinum_conf. Return the index * if found, or -1 if not */ int drive_index(struct drive *drive) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.drives_used; i++) if (&DRIVE[i] == drive) return i; return -1; } /* Check a volume to see if the plex is already assigned to it. * Return index in volume->plex, or -1 if not assigned */ int my_plex(int volno, int plexno) { BROKEN_GDB; int i; struct volume *vol; vol = &VOL[volno]; /* point to volno */ for (i = 0; i < vol->plexes; i++) if (vol->plex[i] == plexno) return i; return -1; /* not found */ } /* Check a plex to see if the subdisk is already assigned to it. * Return index in plex->sd, or -1 if not assigned */ int my_sd(int plexno, int sdno) { BROKEN_GDB; int i; struct plex *plex; plex = &PLEX[plexno]; for (i = 0; i < plex->subdisks; i++) if (plex->sdnos[i] == sdno) return i; return -1; /* not found */ } /* Check that this operation is being done in the kernel. * longjmp out if not. op the name of the operation. */ void checkkernel(char *op) { BROKEN_GDB; if (vinum_conf.flags & VF_KERNELOP == 0) throw_rude_remark(EPERM, "Can't perform '%s' from user space", op); } /* Add plex to the volume if possible */ int give_plex_to_volume(int volno, int plexno) { BROKEN_GDB; struct volume *vol; /* XXX It's not an error for the plex to already * belong to the volume, but we need to check a * number of things to make sure it's done right. * Some day. */ if (my_plex(volno, plexno) >= 0) return plexno; /* that's it */ vol = &VOL[volno]; /* point to volume */ if (vol->plexes == MAXPLEX) /* all plexes allocated */ throw_rude_remark(ENOSPC, "Too many plexes for volume %s", vol->name); vol->plex[vol->plexes] = plexno; /* this one */ vol->plexes++; /* add another plex */ PLEX[plexno].volno = volno; /* note the number of our volume */ return vol->plexes - 1; /* and return its index */ } /* Add subdisk to a plex if possible */ int give_sd_to_plex(int plexno, int sdno) { BROKEN_GDB; int i; struct plex *plex; struct sd *sd; /* XXX It's not an error for the sd to already * belong to the plex, but we need to check a * number of things to make sure it's done right. * Some day. */ i = my_sd(plexno, sdno); if (i >= 0) /* does it already belong to us? */ return i; /* that's it */ plex = &PLEX[plexno]; /* point to the plex */ sd = &SD[sdno]; /* and the subdisk */ /* Do we have an offset? Otherwise put it after the last one */ if (sd->plexoffset < 0) { /* no offset specified */ if (plex->subdisks > 0) { struct sd *lastsd = &SD[plex->sdnos[plex->subdisks - 1]]; /* last subdisk */ sd->plexoffset = lastsd->sectors + lastsd->plexoffset; /* take it */ } else /* first subdisk */ sd->plexoffset = 0; /* start at the beginning */ } plex->subdisks++; /* another entry */ if (plex->subdisks >= plex->subdisks_allocated) /* need more space */ EXPAND(plex->sdnos, int, plex->subdisks_allocated, INITIAL_SUBDISKS_IN_PLEX); /* XXX I'm not sure this makes any sense * for anything except concatenated plexes, * and it comes up with the wrong answer for * RAID-5 plexes, but it's currently needed * for the calculations. We'll adjust for * RAID-5 in config_plex */ if ((sd->sectors + sd->plexoffset) > plex->length) { /* gone beyond the end of the plex */ plex->length = sd->sectors + sd->plexoffset; /* adjust the length */ if ((plex->volno >= 0) /* we have a volume */ &&(plex->length > VOL[plex->volno].size)) /* and we're now the longest plex */ VOL[plex->volno].size = plex->length; /* increase the size of the volume */ } /* We need to check that the subdisks don't overlap, * but we can't do that until a point where we *must* * know the size of all the subdisks. That's not * here. But we need to sort them by offset */ for (i = 0; i < plex->subdisks - 1; i++) { if (sd->plexoffset < SD[plex->sdnos[i]].plexoffset) { /* it fits before this one */ /* First move any remaining subdisks by one */ int j; for (j = plex->subdisks - 1; j > i; j--) /* move up one at a time */ plex->sdnos[j] = plex->sdnos[j - 1]; plex->sdnos[i] = sdno; return i; } } /* The plex doesn't have any subdisk with a larger * offset. Insert it */ plex->sdnos[i] = sdno; return i; } /* Add a subdisk to drive if possible. The pointer to the drive * must already be stored in the sd structure, but the drive * doesn't know about the subdisk yet. */ static void give_sd_to_drive(int sdno) { BROKEN_GDB; struct sd *sd; /* pointer to subdisk */ struct drive *drive; /* and drive */ int fe; /* index in free list */ sd = &SD[sdno]; /* point to sd */ drive = &DRIVE[sd->driveno]; /* and drive */ if (drive->state != drive_up) /* not up */ throw_rude_remark(EIO, "Drive %s is not accessible", drive->label.name); else if (sd->sectors > drive->sectors_available) { /* too big, */ sd->driveoffset = -1; /* don't be confusing */ throw_rude_remark(ENOSPC, "No space for %s on %s", sd->name, drive->label.name); } drive->subdisks_used++; /* one more subdisk */ /* no offset specified, find one */ if (sd->driveoffset < 0) { for (fe = 0; fe < drive->freelist_entries; fe++) { if (drive->freelist[fe].sectors >= sd->sectors) { /* it'll fit here */ sd->driveoffset = drive->freelist[fe].offset; if (sd->sectors == drive->freelist[fe].sectors) { /* used up the entire entry */ if (fe < (drive->freelist_entries - 1)) /* not the last one, */ bcopy(&drive->freelist[fe + 1], &drive->freelist[fe], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry */ } else { drive->freelist[fe].sectors -= sd->sectors; /* this much less space */ drive->freelist[fe].offset += sd->sectors; /* this much further on */ } drive->sectors_available -= sd->sectors; /* and note how much less space we have */ break; } } if (fe == drive->freelist_entries) /* Didn't find anything. Although the drive has * enough space, it's too fragmented */ { sd->driveoffset = -1; /* don't be confusing */ throw_rude_remark(ENOSPC, "No space for %s on %s", sd->name, drive->label.name); } } else { /* specific offset */ /* For a specific offset to work, the space must be * entirely in a single freelist entry. Look for it. */ u_int64_t sdend = sd->driveoffset + sd->sectors; /* end of our subdisk */ for (fe = 0; fe < drive->freelist_entries; fe++) { u_int64_t dend = drive->freelist[fe].offset + drive->freelist[fe].sectors; /* end of entry */ if (dend >= sdend) { /* fits before here */ if (drive->freelist[fe].offset > sd->driveoffset) /* starts after the beginning of sd area */ throw_rude_remark(ENOSPC, "No space for subdisk %s on drive %s at offset %qd\n", sd->name, drive->label.name); /* We've found the space, and we can allocate it. * We don't need to say that to the subdisk, which * already knows about it. We need to tell it to * the free list, though. We have four possibilities: * * 1. The subdisk exactly eats up the entry. That's the * same as above. * 2. The subdisk starts at the beginning and leaves space * at the end. * 3. The subdisk starts after the beginning and leaves * space at the end as well: we end up with another * fragment. * 4. The subdisk leaves space at the beginning and finishes * at the end. */ drive->sectors_available -= sd->sectors; /* note how much less space we have */ if (sd->driveoffset == drive->freelist[fe].offset) { /* 1 or 2 */ if (sd->sectors == drive->freelist[fe].sectors) { /* 1: used up the entire entry */ if (fe < (drive->freelist_entries - 1)) /* not the last one, */ bcopy(&drive->freelist[fe + 1], &drive->freelist[fe], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry */ } else { /* 2: space at the end */ drive->freelist[fe].sectors -= sd->sectors; /* this much less space */ drive->freelist[fe].offset += sd->sectors; /* this much further on */ } } else { /* 3 or 4 */ drive->freelist[fe].sectors = sd->driveoffset - drive->freelist[fe].offset; if (dend > sdend) { /* 3: space at the end as well */ if (fe < (drive->freelist_entries - 1)) /* not the last one */ bcopy(&drive->freelist[fe], /* move the rest down */ &drive->freelist[fe + 1], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries++; /* one less entry */ drive->freelist[fe + 1].offset = sdend; /* second entry starts after sd */ drive->freelist[fe + 1].sectors = dend - sdend; /* and is this long */ } } break; } } } drive->opencount++; /* one more subdisk attached */ } /* Get an empty drive entry from the drive table */ int get_empty_drive(void) { BROKEN_GDB; int driveno; struct drive *drive; /* first see if we have one which has been deallocated */ for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { if (DRIVE[driveno].state == drive_unallocated) /* bingo */ break; } if (driveno >= vinum_conf.drives_used) /* Couldn't find a deallocated drive. Allocate a new one */ { vinum_conf.drives_used++; if (vinum_conf.drives_used > vinum_conf.drives_allocated) /* we've used all our allocation */ EXPAND(DRIVE, struct drive, vinum_conf.drives_allocated, INITIAL_DRIVES); } /* got a drive entry. Make it pretty */ drive = &DRIVE[driveno]; bzero(drive, sizeof(struct drive)); drive->driveno = driveno; /* put number in structure */ return driveno; /* return the index */ } /* Find the named drive in vinum_conf.drive, return a pointer * return the index in vinum_conf.drive. - * Don't mark the drive as allocated (XXX MP) + * Don't mark the drive as allocated (XXX SMP) * If create != 0, create an entry if it doesn't exist */ /* XXX check if we have it open from attach */ int find_drive(const char *name, int create) { BROKEN_GDB; int driveno; struct drive *drive; if (name != NULL) { for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { drive = &DRIVE[driveno]; /* point to drive */ if ((drive->label.name[0] != '\0') /* it has a name */ &&(strcmp(drive->label.name, name) == 0)) /* and it's this one: found */ return driveno; } } /* the drive isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ driveno = get_empty_drive(); drive = &DRIVE[driveno]; if (name != NULL) bcopy(name, /* put in its name */ drive->label.name, min(sizeof(drive->label.name), strlen(name))); drive->state = drive_uninit; /* in use, nothing worthwhile there */ return driveno; /* return the index */ } /* Find a drive given its device name. * devname must be valid. * Otherwise the same as find_drive above */ int find_drive_by_dev(const char *devname, int create) { BROKEN_GDB; int driveno; struct drive *drive; for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { drive = &DRIVE[driveno]; /* point to drive */ if ((drive->label.name[0] != '\0') /* it has a name */ &&(strcmp(drive->label.name, devname) == 0)) /* and it's this one: found */ return driveno; } /* the drive isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ driveno = get_empty_drive(); drive = &DRIVE[driveno]; bcopy(devname, /* put in its name */ drive->devicename, min(sizeof(drive->devicename), strlen(devname))); drive->state = drive_uninit; /* in use, nothing worthwhile there */ return driveno; /* return the index */ } /* Find an empty subdisk in the subdisk table */ int get_empty_sd(void) { BROKEN_GDB; int sdno; struct sd *sd; /* first see if we have one which has been deallocated */ for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { if (SD[sdno].state == sd_unallocated) /* bingo */ break; } if (sdno >= vinum_conf.subdisks_used) { /* No unused sd found. Allocate a new one */ vinum_conf.subdisks_used++; if (vinum_conf.subdisks_used > vinum_conf.subdisks_allocated) EXPAND(SD, struct sd, vinum_conf.subdisks_allocated, INITIAL_SUBDISKS); } /* initialize some things */ sd = &SD[sdno]; /* point to it */ bzero(sd, sizeof(struct sd)); /* initialize */ sd->plexno = -1; /* no plex */ sd->driveno = -1; /* and no drive */ sd->plexoffset = -1; /* and no offsets */ sd->driveoffset = -1; return sdno; /* return the index */ } /* return a drive to the free pool */ void free_drive(struct drive *drive) { BROKEN_GDB; if (drive->vp != NULL) /* device open */ vn_close(drive->vp, FREAD | FWRITE, FSCRED, drive->p); bzero(drive, sizeof(struct drive)); /* this also sets drive_unallocated */ } /* Find the named subdisk in vinum_conf.sd. * If create != 0, create an entry if it doesn't exist * * Return index in vinum_conf.sd */ int find_subdisk(const char *name, int create) { BROKEN_GDB; int sdno; struct sd *sd; for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { if (strcmp(SD[sdno].name, name) == 0) /* found it */ return sdno; } /* the subdisk isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ sdno = get_empty_sd(); sd = &SD[sdno]; bcopy(name, sd->name, min(sizeof(sd->name), strlen(name))); /* put in its name */ return sdno; /* return the pointer */ } /* Free an allocated sd entry * This performs memory management only. remove() * is responsible for checking relationships. */ void free_sd(int sdno) { BROKEN_GDB; struct sd *sd; struct drive *drive; int fe; /* free list entry */ u_int64_t sdend; /* end of our subdisk */ u_int64_t dend; /* end of our freelist entry */ sd = &SD[sdno]; if ((sd->driveno >= 0) /* we have a drive, */ &&(sd->sectors > 0)) { /* and some space on it */ drive = &DRIVE[sd->driveno]; sdend = sd->driveoffset + sd->sectors; /* end of our subdisk */ /* Look for where to return the sd address space */ for (fe = 0; (fe < drive->freelist_entries) && (drive->freelist[fe].offset < sd->driveoffset); fe++); /* Now we are pointing to the last entry, the first * with a higher offset than the subdisk, or both. */ if ((fe > 1) /* not the first entry */ &&((fe == drive->freelist_entries) /* gone past the end */ ||(drive->freelist[fe].offset > sd->driveoffset))) /* or past the block were looking for */ fe--; /* point to the block before */ dend = drive->freelist[fe].offset + drive->freelist[fe].sectors; /* end of the entry */ /* At this point, we are pointing to the correct * place in the free list. A number of possibilities * exist: * * 1. The block to be freed immediately follows * the block to which we are pointing. Just * enlarge it. * 2. The block to be freed starts at the end of * the current block and ends at the beginning * of the following block. Merge the three * areas into a single block. * 3. The block to be freed starts after the end * of the block and ends before the start of * the following block. Create a new free block. * 4. The block to be freed starts after the end * of the block, but ends at the start of the * following block. Enlarge the following block * downwards. * */ if (sd->driveoffset == dend) { /* it starts after the end of this block */ if ((fe < drive->freelist_entries - 1) /* we're not the last block in the free list */ &&(sdend == drive->freelist[fe + 1].offset)) { /* and the subdisk ends at the start of the * next block */ drive->freelist[fe].sectors = drive->freelist[fe + 1].sectors; /* 2: merge all three blocks */ if (fe < drive->freelist_entries - 2) /* still more blocks after next */ bcopy(&drive->freelist[fe + 2], /* move down one */ &drive->freelist[fe + 1], (drive->freelist_entries - 2 - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry in the free list */ } else /* 1: just enlarge this block */ drive->freelist[fe].sectors += sd->sectors; } else { if (sd->driveoffset > dend) /* it starts after this block */ fe++; /* so look at the next block */ if ((fe < drive->freelist_entries) /* we're not the last block in the free list */ &&(sdend == drive->freelist[fe].offset)) { /* and the subdisk ends at the start of * this block: case 4 */ drive->freelist[fe].offset = sd->driveoffset; /* it starts where the sd was */ drive->freelist[fe].sectors += sd->sectors; /* and it's this much bigger */ } else { /* case 3: non-contiguous */ if (fe < drive->freelist_entries) /* not after the last block, */ bcopy(&drive->freelist[fe], /* move the rest up one entry */ &drive->freelist[fe + 1], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries++; /* one less entry */ drive->freelist[fe].offset = sd->driveoffset; /* this entry represents the sd */ drive->freelist[fe].sectors = sd->sectors; } } drive->opencount--; /* one less subdisk attached */ } bzero(sd, sizeof(struct sd)); /* and clear it out */ sd->state = sd_unallocated; } /* Find an empty plex in the plex table */ int get_empty_plex(void) { BROKEN_GDB; int plexno; struct plex *plex; /* if we allocate one */ /* first see if we have one which has been deallocated */ for (plexno = 0; plexno < vinum_conf.plexes_used; plexno++) { if (PLEX[plexno].state == plex_unallocated) /* bingo */ break; /* and get out of here */ } if (plexno >= vinum_conf.plexes_used) { /* Couldn't find a deallocated plex. Allocate a new one */ vinum_conf.plexes_used++; if (vinum_conf.plexes_used > vinum_conf.plexes_allocated) EXPAND(PLEX, struct plex, vinum_conf.plexes_allocated, INITIAL_PLEXES); } /* Found a plex. Give it an sd structure */ plex = &PLEX[plexno]; /* this one is ours */ bzero(plex, sizeof(struct plex)); /* polish it up */ plex->sdnos = (int *) Malloc(sizeof(int) * INITIAL_SUBDISKS_IN_PLEX); /* allocate sd table */ CHECKALLOC(plex->sdnos, "vinum: Can't allocate plex subdisk table"); bzero(plex->sdnos, (sizeof(int) * INITIAL_SUBDISKS_IN_PLEX)); /* do we need this? */ plex->subdisks = 0; /* no subdisks in use */ plex->subdisks_allocated = INITIAL_SUBDISKS_IN_PLEX; /* and we have space for this many */ plex->organization = plex_disorg; /* and it's not organized */ plex->volno = -1; /* no volume yet */ return plexno; /* return the index */ } /* Find the named plex in vinum_conf.plex * If create != 0, create an entry if it doesn't exist * return index in vinum_conf.plex */ int find_plex(const char *name, int create) { BROKEN_GDB; int plexno; struct plex *plex; for (plexno = 0; plexno < vinum_conf.plexes_allocated; plexno++) { if (strcmp(PLEX[plexno].name, name) == 0) /* found it */ return plexno; } /* the plex isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ plexno = get_empty_plex(); plex = &PLEX[plexno]; /* point to it */ bcopy(name, plex->name, min(sizeof(plex->name), strlen(name))); /* put in its name */ return plexno; /* return the pointer */ } /* Free an allocated plex entry * and its associated memory areas */ void free_plex(int plexno) { BROKEN_GDB; struct plex *plex; plex = &PLEX[plexno]; if (plex->sdnos) Free(plex->sdnos); if (plex->lock) Free(plex->lock); if (plex->defective_region) Free(plex->defective_region); if (plex->unmapped_region) Free(plex->unmapped_region); bzero(plex, sizeof(struct plex)); /* and clear it out */ plex->state = plex_unallocated; } /* Find an empty volume in the volume table */ int get_empty_volume(void) { BROKEN_GDB; int volno; struct volume *vol; /* first see if we have one which has been deallocated */ for (volno = 0; volno < vinum_conf.volumes_used; volno++) { if (VOL[volno].state == volume_unallocated) /* bingo */ break; } if (volno >= vinum_conf.volumes_used) /* Couldn't find a deallocated volume. Allocate a new one */ { vinum_conf.volumes_used++; if (vinum_conf.volumes_used > vinum_conf.volumes_allocated) EXPAND(VOL, struct volume, vinum_conf.volumes_allocated, INITIAL_VOLUMES); } /* Now initialize fields */ vol = &VOL[volno]; bzero(vol, sizeof(struct volume)); vol->preferred_plex = -1; /* default to round robin */ vol->preferred_plex = ROUND_ROBIN_READPOL; /* round robin */ return volno; /* return the index */ } /* Find the named volume in vinum_conf.volume. * If create != 0, create an entry if it doesn't exist * return the index in vinum_conf */ int find_volume(const char *name, int create) { BROKEN_GDB; int volno; struct volume *vol; for (volno = 0; volno < vinum_conf.volumes_used; volno++) { if (strcmp(VOL[volno].name, name) == 0) /* found it */ return volno; } /* the volume isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ volno = get_empty_volume(); vol = &VOL[volno]; bcopy(name, vol->name, min(sizeof(vol->name), strlen(name))); /* put in its name */ vol->blocksize = DEV_BSIZE; /* block size of this volume */ return volno; /* return the pointer */ } /* Free an allocated volume entry * and its associated memory areas */ void free_volume(int volno) { BROKEN_GDB; struct volume *vol; vol = &VOL[volno]; bzero(vol, sizeof(struct volume)); /* and clear it out */ vol->state = volume_unallocated; } /* Handle a drive definition. We store the information in the global variable * drive, so we don't need to allocate. * * If we find an error, print a message and return */ void config_drive(void) { BROKEN_GDB; enum drive_label_info partition_status; /* info about the partition */ int parameter; int driveno; /* index of drive in vinum_conf */ struct drive *drive; /* and pointer to it */ if (tokens < 2) /* not enough tokens */ throw_rude_remark(EINVAL, "Drive has no name"); driveno = find_drive(token[1], 1); /* allocate a drive to initialize */ drive = &DRIVE[driveno]; /* and get a pointer */ if (drive->state != drive_uninit) { /* we already know this drive */ /* XXX Check which definition is more up-to-date. Give * preference for the definition on its own drive */ return; /* XXX */ } for (parameter = 2; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_device: parameter++; if (drive->devicename[0] != '\0') { /* we know this drive... */ if (strcmp(drive->devicename, token[parameter])) /* different name */ close_drive(drive); /* close it if it's open */ else /* no change */ break; } bcopy(token[parameter], /* insert device information */ drive->devicename, min(sizeof(drive->devicename), strlen(token[parameter]))); /* open the device and get the configuration */ partition_status = read_drive_label(drive); if (partition_status == DL_CANT_OPEN) { /* not our kind */ close_drive(drive); if (drive->lasterror == EFTYPE) /* wrong kind of partition */ throw_rude_remark(drive->lasterror, "Drive %s has invalid partition type", drive->label.name); else /* I/O error of some kind */ throw_rude_remark(drive->lasterror, "Can't initialize drive %s", drive->label.name); } else if (partition_status == DL_WRONG_DRIVE) { /* valid drive, not ours */ close_drive(drive); throw_rude_remark(drive->lasterror, "Incorrect drive name %s specified for drive %s", token[1], drive->label.name); } break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ drive->state = DriveState(token[parameter]); /* set the state */ break; default: close_drive(drive); throw_rude_remark(EINVAL, "Drive %s, invalid keyword: %s", token[1], token[parameter]); } } - if (drive->devicename[0] == '\0') + if (drive->devicename[0] == '\0') { + drive->state = drive_unallocated; /* deallocate the drive */ throw_rude_remark(EINVAL, "No device name for %s", drive->label.name); - + } } /* Handle a subdisk definition. We store the information in the global variable * sd, so we don't need to allocate. * * If we find an error, print a message and return */ void config_subdisk(void) { BROKEN_GDB; int parameter; int sdno; /* index of sd in vinum_conf */ struct sd *sd; /* and pointer to it */ u_int64_t size; int sectors; /* sector offset value */ int detached = 0; /* set to 1 if this is a detached subdisk */ int sdindex = -1; /* index in plexes subdisk table */ sdno = get_empty_sd(); /* allocate an SD to initialize */ sd = &SD[sdno]; /* and get a pointer */ for (parameter = 1; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_detached: detached = 1; break; case kw_plexoffset: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, bad plex offset alignment: %qd", sd->name, size); else sd->plexoffset = size / DEV_BSIZE; break; case kw_driveoffset: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, bad drive offset alignment: %qd", sd->name, size); else sd->driveoffset = size / DEV_BSIZE; break; case kw_name: ++parameter; bcopy(token[parameter], sd->name, min(sizeof(sd->name), strlen(token[parameter]))); break; case kw_len: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, length %d not multiple of sector size", sd->name, size); else sd->sectors = size / DEV_BSIZE; break; case kw_drive: sd->driveno = find_drive(token[++parameter], 1); /* insert drive information */ break; case kw_plex: sd->plexno = find_plex(token[++parameter], 1); /* insert plex information */ break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ sd->state = SdState(token[parameter]); /* set the state */ break; default: throw_rude_remark(EINVAL, "sd %s, invalid keyword: %s", sd->name, token[parameter]); } } /* Check we have a drive name */ if (sd->driveno < 0) { /* didn't specify a drive */ sd->driveno = current_drive; /* set to the current drive */ if (sd->driveno < 0) /* no current drive? */ throw_rude_remark(EINVAL, "Subdisk %s is not associated with a drive", sd->name); } /* Check for a plex name */ if ((sd->plexno < 0) /* didn't specify a plex */ &&(!detached)) /* and didn't say not to, */ sd->plexno = current_plex; /* set to the current plex */ if (sd->plexno >= 0) sdindex = give_sd_to_plex(sd->plexno, sdno); /* now tell the plex that it has this sd */ sd->sdno = sdno; /* point to our entry in the table */ /* Does the subdisk have a name? If not, give it one */ if (sd->name[0] == '\0') { /* no name */ char sdsuffix[8]; /* form sd name suffix here */ /* Do we have a plex name? */ if (sdindex >= 0) /* we have a plex */ strcpy(sd->name, PLEX[sd->plexno].name); /* take it from there */ else /* no way */ throw_rude_remark(EINVAL, "Unnamed sd is not associated with a plex"); sprintf(sdsuffix, ".s%d", sdindex); /* form the suffix */ strcat(sd->name, sdsuffix); /* and add it to the name */ } /* do we have complete info for this subdisk? */ if (sd->sectors == 0) throw_rude_remark(EINVAL, "sd %s has no length spec", sd->name); if (sd->state == sd_unallocated) /* no state decided, */ sd->state = sd_init; /* at least we're in the game */ /* register the subdisk with the drive. This action * will have the side effect of setting the offset if * we haven't specified one, and causing an error * message if it overlaps with another subdisk. */ give_sd_to_drive(sdno); } /* Handle a plex definition. * If we find an error, print a message, deallocate the nascent plex, and return */ void config_plex(void) { BROKEN_GDB; int parameter; int plexno; /* index of plex in vinum_conf */ struct plex *plex; /* and pointer to it */ int pindex = MAXPLEX; /* index in volume's plex list */ int detached = 0; /* don't give it to a volume */ current_plex = -1; /* forget the previous plex */ plexno = get_empty_plex(); /* allocate a plex */ plex = &PLEX[plexno]; /* and point to it */ plex->plexno = plexno; /* and back to the config */ for (parameter = 1; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_detached: detached = 1; break; case kw_name: { int namedplexno; namedplexno = find_plex(token[++parameter], 0); /* find an existing plex with this name */ if (namedplexno >= 0) throw_rude_remark(EINVAL, "Duplicate plex %s", token[parameter]); } bcopy(token[parameter], /* put in the name */ plex->name, min(MAXPLEXNAME, strlen(token[parameter]))); break; case kw_org: /* plex organization */ switch (get_keyword(token[++parameter], &keyword_set)) { case kw_concat: plex->organization = plex_concat; break; case kw_striped: { int stripesize = sizespec(token[++parameter]); plex->organization = plex_striped; if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */ throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", plex->name, stripesize); else plex->stripesize = stripesize / DEV_BSIZE; break; } default: throw_rude_remark(EINVAL, "Invalid plex organization"); } if (((plex->organization == plex_striped) ) && (plex->stripesize == 0)) /* didn't specify a valid stripe size */ throw_rude_remark(EINVAL, "Need a stripe size parameter"); break; case kw_volume: plex->volno = find_volume(token[++parameter], 1); /* insert a pointer to the volume */ break; case kw_sd: /* add a subdisk */ { int sdno; sdno = find_subdisk(token[++parameter], 1); /* find a subdisk */ SD[sdno].plexoffset = sizespec(token[++parameter]); /* get the offset */ give_sd_to_plex(plexno, sdno); /* and insert it there */ break; } case kw_state: checkkernel(token[++parameter]); /* only for kernel use */ plex->state = PlexState(token[parameter]); /* set the state */ break; default: throw_rude_remark(EINVAL, "plex %s, invalid keyword: %s", plex->name, token[parameter]); } } if ((plex->volno < 0) /* we don't have a volume */ &&(!detached)) /* and we wouldn't object */ plex->volno = current_volume; if (plex->volno >= 0) pindex = give_plex_to_volume(plex->volno, plexno); /* Now tell the volume that it has this plex */ /* Does the plex have a name? If not, give it one */ if (plex->name[0] == '\0') { /* no name */ char plexsuffix[8]; /* form plex name suffix here */ /* Do we have a volume name? */ if (plex->volno >= 0) /* we have a volume */ strcpy(plex->name, /* take it from there */ VOL[plex->volno].name); else /* no way */ throw_rude_remark(EINVAL, "Unnamed plex is not associated with a volume"); sprintf(plexsuffix, ".p%d", pindex); /* form the suffix */ strcat(plex->name, plexsuffix); /* and add it to the name */ } /* Note the last plex we configured */ current_plex = plexno; if (plex->state == plex_unallocated) /* we haven't changed the state, */ plex->state = plex_init; /* we're initialized now */ } /* Handle a volume definition. * If we find an error, print a message, deallocate the nascent volume, and return */ void config_volume(void) { BROKEN_GDB; int parameter; int volno; struct volume *vol; /* collect volume info here */ int i; if (tokens < 2) /* not enough tokens */ throw_rude_remark(EINVAL, "Volume has no name"); current_volume = -1; /* forget the previous volume */ volno = find_volume(token[1], 1); /* allocate a volume to initialize */ vol = &VOL[volno]; /* and get a pointer */ for (parameter = 2; parameter < tokens; parameter++) { /* look at all tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_plex: { int plexno; /* index of this plex */ plexno = find_plex(token[++parameter], 1); /* find a plex */ if (plexno < 0) /* couldn't */ break; /* we've already had an error message */ plexno = my_plex(volno, plexno); /* does it already belong to us? */ if (plexno > 0) /* yes, shouldn't get it again */ throw_rude_remark(EINVAL, "Plex %s already belongs to volume %s", token[parameter], vol->name); else if (++vol->plexes > 8) /* another entry */ throw_rude_remark(EINVAL, "Too many plexes for volume %s", vol->name); vol->plex[vol->plexes - 1] = plexno; } break; case kw_readpol: switch (get_keyword(token[++parameter], &keyword_set)) { /* decide what to do */ case kw_round: vol->preferred_plex = ROUND_ROBIN_READPOL; /* default */ break; case kw_prefer: { int myplexno; /* index of this plex */ myplexno = find_plex(token[++parameter], 1); /* find a plex */ if (myplexno < 0) /* couldn't */ break; /* we've already had an error message */ myplexno = my_plex(volno, myplexno); /* does it already belong to us? */ if (myplexno > 0) /* yes */ vol->preferred_plex = myplexno; /* just note the index */ else if (++vol->plexes > 8) /* another entry */ throw_rude_remark(EINVAL, "Too many plexes"); else { /* space for the new plex */ vol->plex[vol->plexes - 1] = myplexno; /* add it to our list */ vol->preferred_plex = vol->plexes - 1; /* and note the index */ } } break; default: throw_rude_remark(EINVAL, "Invalid read policy"); } case kw_setupstate: vol->flags |= VF_CONFIG_SETUPSTATE; /* set the volume up later on */ break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ vol->state = VolState(token[parameter]); /* set the state */ break; /* XXX experimental ideas. These are not * documented, and will not be until I * decide they're worth keeping */ case kw_writethrough: /* set writethrough mode */ vol->flags |= VF_WRITETHROUGH; break; case kw_writeback: /* set writeback mode */ vol->flags &= ~VF_WRITETHROUGH; break; case kw_raw: vol->flags |= VF_RAW; /* raw volume (no label) */ break; default: throw_rude_remark(EINVAL, "volume %s, invalid keyword: %s", vol->name, token[parameter]); } } current_volume = volno; /* note last referred volume */ vol->devno = VINUMBDEV(volno, 0, 0, VINUM_VOLUME_TYPE); /* also note device number */ /* Before we can actually use the volume, we need * a volume label. We could start to fake one here, * but it will be a lot easier when we have some * to copy from the drives, so defer it until we * set up the configuration. XXX */ if (vol->state == volume_unallocated) vol->state = volume_down; /* now ready to bring up at the end */ /* Find out how big our volume is */ for (i = 0; i < vol->plexes; i++) vol->size = max(vol->size, PLEX[vol->plex[i]].length); } /* Parse a config entry. CARE! This destroys the original contents of the * config entry, which we don't really need after this. More specifically, it * places \0 characters at the end of each token. * * Return 0 if all is well, otherwise EINVAL */ int parse_config(char *cptr, struct keywordset *keyset) { BROKEN_GDB; int status; status = 0; /* until proven otherwise */ tokens = tokenize(cptr, token); /* chop up into tokens */ if (tokens <= 0) /* screwed up or empty line */ return tokens; /* give up */ if (token[0][0] == '#') /* comment line */ return 0; switch (get_keyword(token[0], keyset)) { /* decide what to do */ case kw_read: /* read config from a specified drive */ vinum_conf.flags |= VF_KERNELOP | VF_READING_CONFIG; /* kernel operation: reading config */ status = check_drive(token[1]); /* check the drive info */ vinum_conf.flags &= ~(VF_KERNELOP | VF_READING_CONFIG); if (status != 0) { char *msg = "Can't read configuration from %s"; if (status == ENODEV) msg = "No vinum configuration on %s"; throw_rude_remark(status, msg, token[1]); } updateconfig(VF_KERNELOP); /* update from kernel space */ break; case kw_drive: config_drive(); break; case kw_subdisk: config_subdisk(); break; case kw_plex: config_plex(); break; case kw_volume: config_volume(); break; /* Anything else is invalid in this context */ default: throw_rude_remark(EINVAL, /* should we die? */ "Invalid configuration information: %s", token[0]); } return status; } /* parse a line handed in from userland via ioctl. * This differs only by the error reporting mechanism: * we return the error indication in the reply to the * ioctl, so we need to set a global static pointer in * this file. This technique works because we have * ensured that configuration is performed in a single- * threaded manner */ int parse_user_config(char *cptr, struct keywordset *keyset) { BROKEN_GDB; int status; ioctl_reply = (struct _ioctl_reply *) cptr; status = parse_config(cptr, keyset); ioctl_reply = NULL; /* don't do this again */ return status; } /* Remove an object */ void remove(struct vinum_ioctl_msg *msg) { struct vinum_ioctl_msg message = *msg; /* make a copy to hand on */ ioctl_reply = (struct _ioctl_reply *) msg; /* reinstate the address to reply to */ ioctl_reply->error = 0; /* no error, */ ioctl_reply->msg[0] = '\0'; /* no message */ switch (message.type) { case drive_object: remove_drive_entry(message.index, message.force, message.recurse); updateconfig(0); return; case sd_object: remove_sd_entry(message.index, message.force, message.recurse); updateconfig(0); return; case plex_object: remove_plex_entry(message.index, message.force, message.recurse); updateconfig(0); return; case volume_object: remove_volume_entry(message.index, message.force, message.recurse); updateconfig(0); return; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); } } /* Remove a drive. */ void remove_drive_entry(int driveno, int force, int recurse) { struct drive *drive = &DRIVE[driveno]; if ((driveno > vinum_conf.drives_used) /* not a valid drive */ ||(drive->state == drive_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such drive"); } else if (drive->opencount > 0) { /* we have subdisks */ if (force) { /* do it at any cost */ int sdno; struct vinum_ioctl_msg sdmsg; for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { if ((SD[sdno].state != sd_unallocated) /* subdisk is allocated */ &&(SD[sdno].driveno == driveno)) { /* and it belongs to this drive */ sdmsg.type = sd_object; sdmsg.recurse = 1; sdmsg.force = force; remove(&sdmsg); /* remove the subdisk by force */ } } remove_drive(driveno); /* now remove it */ } else ioctl_reply->error = EBUSY; /* can't do that */ } else remove_drive(driveno); /* just remove it */ } /* remove a subdisk */ void remove_sd_entry(int sdno, int force, int recurse) { struct sd *sd = &SD[sdno]; if ((sdno > vinum_conf.subdisks_used) /* not a valid sd */ ||(sd->state == sd_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such subdisk"); } else if (sd->plexno >= 0) { /* we have a plex */ if (force) { /* do it at any cost */ struct plex *plex = &PLEX[sd->plexno]; /* point to our plex */ int mysdno; for (mysdno = 0; /* look for ourselves */ mysdno < plex->subdisks && &SD[plex->sdnos[mysdno]] != sd; mysdno++); if (mysdno == plex->subdisks) /* didn't find it */ throw_rude_remark(ENOENT, "plex %s does not contain subdisk %s", plex->name, sd->name); if (mysdno < (plex->subdisks - 1)) /* not the last subdisk */ bcopy(&plex->sdnos[mysdno + 1], &plex->sdnos[mysdno], (plex->subdisks - 1 - mysdno) * sizeof(int)); plex->subdisks--; /* removing a subdisk from a striped or * RAID-5 plex really tears the hell out * of the structure, and it needs to be * reinitialized */ if (plex->organization != plex_concat) /* not concatenated, */ set_plex_state(plex->plexno, plex_faulty, setstate_force); /* need to reinitialize */ rebuild_plex_unmappedlist(plex); /* and see what remains */ free_sd(sdno); } else ioctl_reply->error = EBUSY; /* can't do that */ } else free_sd(sdno); } /* remove a plex */ void remove_plex_entry(int plexno, int force, int recurse) { struct plex *plex = &PLEX[plexno]; int sdno; if ((plexno > vinum_conf.plexes_used) /* not a valid plex */ ||(plex->state == plex_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such plex"); } else if (plex->pid) { /* we're open */ ioctl_reply->error = EBUSY; /* no getting around that */ return; } if (plex->subdisks) { if (force) { /* do it anyway */ if (recurse) { /* remove all below */ for (sdno = 0; sdno < plex->subdisks; sdno++) free_sd(plex->sdnos[sdno]); /* free all subdisks */ } else { /* just tear them out */ for (sdno = 0; sdno < plex->subdisks; sdno++) SD[plex->sdnos[sdno]].plexno = -1; /* no plex any more */ } } else { /* can't do it without force */ ioctl_reply->error = EBUSY; /* can't do that */ return; } } if (plex->volno >= 0) { /* we are part of a volume */ /* XXX This should be more intelligent. We should * be able to remove a plex as long as the volume * does not lose any data, which is normally the * case when it has more than one plex. To do it * right we must compare the completeness of the * mapping of all the plexes in the volume */ if (force) { /* do it at any cost */ struct volume *vol = &VOL[plex->volno]; int myplexno; for (myplexno = 0; myplexno < vol->plexes; myplexno++) if (vol->plex[myplexno] == plexno) /* found it */ break; if (myplexno == vol->plexes) /* didn't find it. Huh? */ throw_rude_remark(ENOENT, "volume %s does not contain plex %s", vol->name, plex->name); if (myplexno < (vol->plexes - 1)) /* not the last plex in the list */ bcopy(&vol->plex[myplexno + 1], &vol->plex[myplexno], vol->plexes - 1 - myplexno); vol->plexes--; } else { ioctl_reply->error = EBUSY; /* can't do that */ return; } } free_plex(plexno); } /* remove a volume */ void remove_volume_entry(int volno, int force, int recurse) { struct volume *vol = &VOL[volno]; int plexno; if ((volno > vinum_conf.volumes_used) /* not a valid volume */ ||(vol->state == volume_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such volume"); } else if (vol->opencount) /* we're open */ ioctl_reply->error = EBUSY; /* no getting around that */ else if (vol->plexes) { if (recurse && force) { /* remove all below */ struct vinum_ioctl_msg plexmsg; plexmsg.type = plex_object; plexmsg.recurse = 1; plexmsg.force = force; for (plexno = 0; plexno < vol->plexes; plexno++) { plexmsg.index = vol->plex[plexno]; /* plex number */ remove(&plexmsg); } free_volume(volno); } else ioctl_reply->error = EBUSY; /* can't do that */ } else free_volume(volno); } void update_sd_config(int sdno, int kernelstate) { if (!kernelstate) set_sd_state(sdno, sd_up, setstate_configuring | setstate_norecurse); } void update_plex_config(int plexno, int kernelstate) { int error = 0; int size; int sdno; struct plex *plex = &PLEX[plexno]; enum plexstate state = plex_up; /* state we want the plex in */ /* XXX Insert checks here for sparse plexes and volumes */ /* Check that our subdisks make sense. For * striped and RAID5 plexes, we need at least * two subdisks, and they must all be the same * size */ if (((plex->organization == plex_striped) ) && (plex->subdisks < 2)) { error = 1; printf("vinum: plex %s does not have at least 2 subdisks\n", plex->name); if (!kernelstate) set_plex_state(plexno, plex_down, setstate_force | setstate_configuring | setstate_norecurse); } size = 0; for (sdno = 0; sdno < plex->subdisks; sdno++) { if (((plex->organization == plex_striped) ) && (sdno > 0) && (SD[plex->sdnos[sdno]].sectors != SD[plex->sdnos[sdno - 1]].sectors)) { error = 1; printf("vinum: plex %s must have equal sized subdisks\n", plex->name); set_plex_state(plexno, plex_down, setstate_force | setstate_configuring | setstate_norecurse); } size += SD[plex->sdnos[sdno]].sectors; } if (plex->subdisks) { /* plex has subdisks, calculate size */ rebuild_plex_unmappedlist(plex); /* rebuild the unmapped list first */ plex->length = size; } else { /* no subdisks, */ plex->length = 0; /* no size */ state = plex_down; /* take it down */ } if (!(kernelstate || error)) set_plex_state(plexno, state, setstate_none | setstate_configuring | setstate_norecurse); } void update_volume_config(int volno, int kernelstate) { struct volume *vol = &VOL[volno]; struct plex *plex; int plexno; if (vol->state != volume_unallocated) /* Recalculate the size of the volume */ { vol->size = 0; for (plexno = 0; plexno < vol->plexes; plexno++) { plex = &PLEX[vol->plex[plexno]]; vol->size = max(plex->length, vol->size); /* maximum size */ plex->volplexno = plexno; /* note it in the plex */ } } if (!kernelstate) /* try to bring it up */ set_volume_state(volno, volume_up, setstate_configuring | setstate_norecurse); } /* Update the global configuration. * kernelstate is != 0 if we're reading in a config * from disk. In this case, we don't try to * bring the devices up, though we will bring * them down if there's some error which got * missed when writing to disk. */ void updateconfig(int kernelstate) { BROKEN_GDB; int sdno; int plexno; int volno; struct volume *vol; struct plex *plex; for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) update_sd_config(sdno, kernelstate); for (plexno = 0; plexno < vinum_conf.plexes_used; plexno++) update_plex_config(plexno, kernelstate); for (volno = 0; volno < vinum_conf.volumes_used; volno++) update_volume_config(volno, kernelstate); save_config(); } /* Start manual changes to the configuration and lock out * others who may wish to do so. * XXX why do we need this and lock_config too? */ int start_config(void) { int error; while ((vinum_conf.flags & VF_CONFIGURING) != 0) { vinum_conf.flags |= VF_WILL_CONFIGURE; if ((error = tsleep(&vinum_conf, PRIBIO | PCATCH, "vincfg", 0)) != 0) return error; } /* We need two flags here: VF_CONFIGURING * tells other processes to hold off (this * function), and VF_CONFIG_INCOMPLETE * tells the state change routines not to * propagate incrememntal state changes */ vinum_conf.flags |= VF_CONFIGURING | VF_CONFIG_INCOMPLETE; current_drive = -1; /* reset the defaults */ current_plex = -1; /* and the same for the last plex */ current_volume = -1; /* and the last volme */ return 0; } /* Update the config if update is 1, and unlock * it. We won't update the configuration if we * are called in a recursive loop via throw_rude_remark. */ void finish_config(int update) { vinum_conf.flags &= ~VF_CONFIG_INCOMPLETE; /* we've finished our config */ if (update) updateconfig(0); /* so update things */ else updateconfig(1); /* do some updates only */ vinum_conf.flags &= ~VF_CONFIGURING; /* and now other people can take a turn */ if ((vinum_conf.flags & VF_WILL_CONFIGURE) != 0) { vinum_conf.flags &= ~VF_WILL_CONFIGURE; wakeup(&vinum_conf); } } diff --git a/lkm/vinum/interrupt.c b/lkm/vinum/interrupt.c index e7eb034faf4b..1557cfe69d3e 100644 --- a/lkm/vinum/interrupt.c +++ b/lkm/vinum/interrupt.c @@ -1,190 +1,194 @@ /* interrupt.c: bottom half of the driver */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: interrupt.c,v 1.1 1998/08/13 06:12:27 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" #include #include void complete_raid5_write(struct rqelement *); void freerq(struct request *rq); void free_rqg(struct rqgroup *rqg); void complete_rqe(struct buf *bp); void sdio_done(struct buf *bp); /* Take a completed buffer, transfer the data back if * it's a read, and complete the high-level request * if this is the last subrequest. * * The bp parameter is in fact a struct rqelement, which * includes a couple of extras at the end. */ void complete_rqe(struct buf *bp) { BROKEN_GDB; struct rqelement *rqe; struct request *rq; struct rqgroup *rqg; struct buf *ubp; /* user buffer */ rqe = (struct rqelement *) bp; /* point to the element element that completed */ rqg = rqe->rqg; /* and the request group */ rq = rqg->rq; /* and the complete request */ + ubp = rq->bp; /* user buffer */ +#ifdef DEBUG + if (debug & DEBUG_LASTREQS) + logrq(loginfo_iodone, rqe, ubp); +#endif if ((bp->b_flags & B_ERROR) != 0) { /* transfer in error */ if (bp->b_error != 0) /* did it return a number? */ rq->error = bp->b_error; /* yes, put it in. */ else if (rq->error == 0) /* no: do we have one already? */ rq->error = EIO; /* no: catchall "I/O error" */ if (rq->error == EIO) /* I/O error, */ - set_sd_state(rqe->sdno, sd_crashed, setstate_force); /* take the subdisk down */ + set_sd_state(rqe->sdno, sd_crashed, setstate_force | setstate_noupdate); /* take the subdisk down */ } /* Now update the statistics */ if (bp->b_flags & B_READ) { /* read operation */ DRIVE[rqe->driveno].reads++; DRIVE[rqe->driveno].bytes_read += bp->b_bcount; SD[rqe->sdno].reads++; SD[rqe->sdno].bytes_read += bp->b_bcount; PLEX[rqe->rqg->plexno].reads++; PLEX[rqe->rqg->plexno].bytes_read += bp->b_bcount; } else { /* write operation */ DRIVE[rqe->driveno].writes++; DRIVE[rqe->driveno].bytes_written += bp->b_bcount; SD[rqe->sdno].writes++; SD[rqe->sdno].bytes_written += bp->b_bcount; PLEX[rqe->rqg->plexno].writes++; PLEX[rqe->rqg->plexno].bytes_written += bp->b_bcount; } - ubp = rq->bp; /* user buffer */ rqg->active--; /* one less request active */ if (rqg->active == 0) /* request group finished, */ rq->active--; /* one less */ if (rq->active == 0) { /* request finished, */ #if DEBUG - if (debug & 4) { + if (debug & DEBUG_RESID) { if (ubp->b_resid != 0) /* still something to transfer? */ Debugger("resid"); { int i; for (i = 0; i < ubp->b_bcount; i += 512) /* XXX debug */ if (((char *) ubp->b_data)[i] != '<') { /* and not what we expected */ printf("At 0x%x (offset 0x%x): '%c' (0x%x)\n", (int) (&((char *) ubp->b_data)[i]), i, ((char *) ubp->b_data)[i], ((char *) ubp->b_data)[i]); Debugger("complete_request checksum"); } } } #endif if (rq->error) { /* did we have an error? */ ubp->b_flags |= B_ERROR; /* yes, propagate to user */ ubp->b_error = rq->error; } else ubp->b_resid = 0; /* completed our transfer */ if (rq->isplex == 0) /* volume request, */ VOL[rq->volplex.volno].active--; /* another request finished */ biodone(ubp); /* top level buffer completed */ freerq(rq); /* return the request storage */ } } /* Free a request block and anything hanging off it */ void freerq(struct request *rq) { BROKEN_GDB; struct rqgroup *rqg; struct rqgroup *nrqg; /* next in chain */ int rqno; for (rqg = rq->rqg; rqg != NULL; rqg = nrqg) { /* through the whole request chain */ for (rqno = 0; rqno < rqg->count; rqno++) if ((rqg->rqe[rqno].flags & XFR_MALLOCED) /* data buffer was malloced, */ &&rqg->rqe[rqno].b.b_data) /* and the allocation succeeded */ Free(rqg->rqe[rqno].b.b_data); /* free it */ nrqg = rqg->next; /* note the next one */ Free(rqg); /* and free this one */ } Free(rq); /* free the request itself */ } void free_rqg(struct rqgroup *rqg) { if ((rqg->flags & XFR_GROUPOP) /* RAID 5 request */ &&(rqg->rqe) /* got a buffer structure */ &&(rqg->rqe->b.b_data)) /* and it has a buffer allocated */ Free(rqg->rqe->b.b_data); /* free it */ } /* I/O on subdisk completed */ void sdio_done(struct buf *bp) { struct sdbuf *sbp; sbp = (struct sdbuf *) bp; if (sbp->b.b_flags & B_ERROR) { /* had an error */ bp->b_flags |= B_ERROR; bp->b_error = sbp->b.b_error; } bp->b_resid = sbp->b.b_resid; biodone(sbp->bp); /* complete the caller's I/O */ /* Now update the statistics */ if (bp->b_flags & B_READ) { /* read operation */ DRIVE[sbp->driveno].reads++; DRIVE[sbp->driveno].bytes_read += bp->b_bcount; SD[sbp->sdno].reads++; SD[sbp->sdno].bytes_read += bp->b_bcount; } else { /* write operation */ DRIVE[sbp->driveno].writes++; DRIVE[sbp->driveno].bytes_written += bp->b_bcount; SD[sbp->sdno].writes++; SD[sbp->sdno].bytes_written += bp->b_bcount; } Free(sbp); } diff --git a/lkm/vinum/memory.c b/lkm/vinum/memory.c index 5dee671167b0..e77af7e82f5e 100644 --- a/lkm/vinum/memory.c +++ b/lkm/vinum/memory.c @@ -1,186 +1,198 @@ - /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: memory.c,v 1.16 1998/08/08 04:43:22 grog Exp grog $ + * $Id: memory.c,v 1.17 1998/09/29 05:18:09 grog Exp grog $ */ #define REALLYKERNEL #define USES_VM #include "vinumhdr.h" extern jmp_buf command_fail; /* return on a failed command */ +#ifdef DEBUG +#include "request.h" +extern struct rqinfo rqinfo[]; +extern struct rqinfo *rqip; +#endif + #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ int setjmp(jmp_buf); void longjmp(jmp_buf, int); #endif void freedatabuf(struct mc *me); caddr_t allocdatabuf(struct mc *me); void expand_table(void **table, int oldsize, int newsize) { if (newsize > oldsize) { int *temp; temp = (int *) Malloc(newsize); /* allocate a new table */ CHECKALLOC(temp, "vinum: Can't expand table\n"); if (*table != NULL) { /* already something there, */ bcopy((char *) *table, (char *) temp, oldsize); /* copy it to the old table */ Free(*table); } *table = temp; } } -#ifndef DEBUG -/* increase the size of a request block */ -void -expandrq(struct plexrq *prq) -{ - expand_table((void **) &prq->rqe, - prq->requests * sizeof(struct rqelement), - (prq->requests + RQELTS) * sizeof(struct rqelement)); - bzero(&prq->rqe[prq->requests], RQELTS * sizeof(struct rqelement)); /* clear the new part */ - prq->rqcount += RQELTS; -} - -#endif - #if DEBUG /* XXX debug */ #define MALLOCENTRIES 16384 int malloccount = 0; int highwater = 0; /* highest index ever allocated */ static struct mc malloced[MALLOCENTRIES]; static total_malloced; caddr_t MMalloc(int size, char *file, int line) { caddr_t result; int i; static int seq = 0; int s; struct mc me; /* information to pass to allocdatabuf */ if (malloccount >= MALLOCENTRIES) { /* too many */ printf("vinum: can't allocate table space to trace memory allocation"); return 0; /* can't continue */ } result = malloc(size, M_DEVBUF, M_WAITOK); /* use malloc for smaller and irregular stuff */ if (result == NULL) printf("vinum: can't allocate %d bytes from %s:%d\n", size, file, line); else { me.flags = 0; /* allocation via malloc */ s = splhigh(); for (i = 0; i < malloccount; i++) { if (((result + size) > malloced[i].address) && (result < malloced[i].address + malloced[i].size)) /* overlap */ Debugger("Malloc overlap"); } if (result) { + char *f = index(file, '/'); /* chop off dirname if present */ + + if (f == NULL) + f = file; i = malloccount++; total_malloced += size; malloced[i].address = result; malloced[i].size = size; malloced[i].line = line; malloced[i].seq = seq++; malloced[i].flags = me.flags; malloced[i].databuf = me.databuf; /* only used with kva alloc */ - bcopy(file, malloced[i].file, min(strlen(file) + 1, 16)); + bcopy(f, malloced[i].file, min(strlen(f) + 1, 16)); } if (malloccount > highwater) highwater = malloccount; splx(s); } return result; } void FFree(void *mem, char *file, int line) { int i; int s; s = splhigh(); for (i = 0; i < malloccount; i++) { if ((caddr_t) mem == malloced[i].address) { /* found it */ bzero(mem, malloced[i].size); /* XXX */ free(mem, M_DEVBUF); malloccount--; total_malloced -= malloced[i].size; if (i < malloccount) /* more coming after */ bcopy(&malloced[i + 1], &malloced[i], (malloccount - i) * sizeof(struct mc)); splx(s); return; } } splx(s); printf("Freeing unallocated data at 0x%08x from %s, line %d\n", (int) mem, file, line); Debugger("Free"); } void vinum_meminfo(caddr_t data) { struct meminfo *m = (struct meminfo *) data; m->mallocs = malloccount; m->total_malloced = total_malloced; m->malloced = malloced; m->highwater = highwater; } int vinum_mallocinfo(caddr_t data) { struct mc *m = (struct mc *) data; unsigned int ent = *(int *) data; /* 1st word is index */ if (ent >= malloccount) return ENOENT; m->address = malloced[ent].address; m->size = malloced[ent].size; m->line = malloced[ent].line; m->seq = malloced[ent].seq; bcopy(malloced[ent].file, m->file, 16); return 0; } +/* return the nth request trace buffer entry. This + * is indexed back from the current entry (which + * has index 0) */ +int +vinum_rqinfo(caddr_t data) +{ + struct rqinfo *rq = (struct rqinfo *) data; + int ent = *(int *) data; /* 1st word is index */ + int lastent = rqip - rqinfo; /* entry number of current entry */ + + if (ent >= RQINFO_SIZE) /* out of the table */ + return ENOENT; + if ((ent = lastent - ent - 1) < 0) + ent += RQINFO_SIZE; /* roll over backwards */ + bcopy(&rqinfo[ent], rq, sizeof(struct rqinfo)); + return 0; +} #endif diff --git a/lkm/vinum/request.c b/lkm/vinum/request.c index 589eb3fac0ba..94df5b9f06bc 100644 --- a/lkm/vinum/request.c +++ b/lkm/vinum/request.c @@ -1,882 +1,947 @@ /* XXX to do: * Decide where we need splbio () */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: request.c,v 1.17 1998/08/13 06:04:47 grog Exp grog $ + * $Id: request.c,v 1.18 1998/08/31 23:45:35 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" #include #include /* pointer to ioctl p parameter, to save passing it around */ extern struct proc *myproc; enum requeststatus bre(struct request *rq, int plexno, daddr_t * diskstart, daddr_t diskend); enum requeststatus bre5(struct request *rq, int plexno, daddr_t * diskstart, daddr_t diskend); enum requeststatus build_read_request(struct request *rq, int volplexno); enum requeststatus build_write_request(struct request *rq); enum requeststatus build_rq_buffer(struct rqelement *rqe, struct plex *plex); void freerq(struct request *rq); void free_rqg(struct rqgroup *rqg); int find_alternate_sd(struct request *rq); int check_range_covered(struct request *); void complete_rqe(struct buf *bp); void complete_raid5_write(struct rqelement *); int abortrequest(struct request *rq, int error); void sdio(struct buf *bp); void sdio_done(struct buf *bp); int vinum_bounds_check(struct buf *bp, struct volume *vol); caddr_t allocdatabuf(struct rqelement *rqe); void freedatabuf(struct rqelement *rqe); +#ifdef DEBUG +struct rqinfo rqinfo[RQINFO_SIZE]; +struct rqinfo *rqip = rqinfo; + +void +logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp) +{ + BROKEN_GDB; + int s = splhigh(); + + vinum_conf.rqipp = &rqip; /* XXX for broken gdb */ + vinum_conf.rqinfop = rqinfo; /* XXX for broken gdb */ + +#if __FreeBSD__ < 3 + rqip->timestamp = time; /* when did this happen? */ +#else + microtime(&rqip->timestamp); /* when did this happen? */ +#endif + rqip->type = type; + rqip->bp = ubp; /* user buffer */ + switch (type) { + case loginfo_user_bp: + case loginfo_user_bpl: + bcopy(info.bp, &rqip->info.b, sizeof(struct buf)); + break; + + case loginfo_iodone: + case loginfo_rqe: + case loginfo_raid5_data: + case loginfo_raid5_parity: + bcopy(info.rqe, &rqip->info.rqe, sizeof(struct rqelement)); + break; + + case loginfo_unused: + break; + } + rqip++; + if (rqip >= &rqinfo[RQINFO_SIZE]) /* wrap around */ + rqip = rqinfo; + splx(s); +} + +#endif + void vinumstrategy(struct buf *bp) { BROKEN_GDB; int volno; struct volume *vol = NULL; int s; struct devcode *device = (struct devcode *) &bp->b_dev; /* decode device number */ enum requeststatus status; + /* We may have changed the configuration in + * an interrupt context. Update it now. It + * could change again, so do it in a loop. + * XXX this is broken and contains a race condition. + * The correct way is to hand it off the the Vinum + * daemon, but I haven't found a name for it yet */ + while (vinum_conf.flags & VF_DIRTYCONFIG) { /* config is dirty, save it now */ + vinum_conf.flags &= ~VF_DIRTYCONFIG; /* turn it off */ + save_config(); + } + switch (device->type) { case VINUM_SD_TYPE: sdio(bp); return; /* In fact, vinum doesn't handle drives: they're * handled directly by the disk drivers */ case VINUM_DRIVE_TYPE: default: bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; biodone(bp); return; case VINUM_VOLUME_TYPE: /* volume I/O */ volno = VOLNO(bp->b_dev); vol = &VOL[volno]; if (vol->state != volume_up) { /* can't access this volume */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; biodone(bp); return; } if (vinum_bounds_check(bp, vol) <= 0) { /* don't like them bounds */ biodone(bp); /* have nothing to do with this */ return; } /* FALLTHROUGH */ /* Plex I/O is pretty much the same as volume I/O * for a single plex. Indicate this by passing a NULL * pointer (set above) for the volume */ case VINUM_PLEX_TYPE: bp->b_resid = bp->b_bcount; /* transfer everything */ vinumstart(bp, 0); return; } } /* Start a transfer. Return -1 on error, * 0 if OK, 1 if we need to retry. * Parameter reviveok is set when doing * transfers for revives: it allows transfers to * be started immediately when a revive is in * progress. During revive, normal transfers * are queued if they share address space with * a currently active revive operation. */ int vinumstart(struct buf *bp, int reviveok) { BROKEN_GDB; int plexno; int maxplex; /* maximum number of plexes to handle */ struct volume *vol; struct rqgroup *rqg; /* current plex's requests */ struct rqelement *rqe; /* individual element */ struct request *rq; /* build up our request here */ int rqno; /* index in request list */ enum requeststatus status; +#if DEBUG + if (debug & DEBUG_LASTREQS) + logrq(loginfo_user_bp, bp, bp); +#endif + /* XXX In these routines, we're assuming that * we will always be called with bp->b_bcount * which is a multiple of the sector size. This * is a reasonable assumption, since we are only * called from system routines. Should we check * anyway? */ if ((bp->b_bcount % DEV_BSIZE) != 0) { /* bad length */ bp->b_error = EINVAL; /* invalid size */ bp->b_flags |= B_ERROR; biodone(bp); return -1; } rq = (struct request *) Malloc(sizeof(struct request)); /* allocate a request struct */ if (rq == NULL) { /* can't do it */ bp->b_error = ENOMEM; /* can't get memory */ bp->b_flags |= B_ERROR; biodone(bp); return -1; } bzero(rq, sizeof(struct request)); /* Note the volume ID. This can be NULL, which * the request building functions use as an * indication for single plex I/O */ rq->bp = bp; /* and the user buffer struct */ if (DEVTYPE(bp->b_dev) == VINUM_VOLUME_TYPE) { /* it's a volume, */ rq->volplex.volno = VOLNO(bp->b_dev); /* get the volume number */ vol = &VOL[rq->volplex.volno]; /* and point to it */ vol->active++; /* one more active request */ maxplex = vol->plexes; /* consider all its plexes */ } else { vol = NULL; /* no volume */ rq->volplex.plexno = PLEXNO(bp->b_dev); /* point to the plex */ rq->isplex = 1; /* note that it's a plex */ maxplex = 1; /* just the one plex */ } if (bp->b_flags & B_READ) { /* This is a read request. Decide * which plex to read from. * * There's a potential race condition here, * since we're not locked, and we could end * up multiply incrementing the round-robin * counter. This doesn't have any serious * effects, however. */ if (vol != NULL) { vol->reads++; vol->bytes_read += bp->b_bcount; plexno = vol->preferred_plex; /* get the plex to use */ if (plexno < 0) { /* round robin */ plexno = vol->last_plex_read; vol->last_plex_read++; if (vol->last_plex_read == vol->plexes) /* got the the end? */ vol->last_plex_read = 0; /* wrap around */ } status = build_read_request(rq, plexno); /* build a request */ } else { daddr_t diskaddr = bp->b_blkno; /* start offset of transfer */ status = bre(rq, /* build a request list */ rq->volplex.plexno, &diskaddr, diskaddr + (bp->b_bcount / DEV_BSIZE)); } if ((status > REQUEST_RECOVERED) /* can't satisfy it */ ||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */ if (status == REQUEST_DOWN) { /* not enough subdisks */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; } biodone(bp); freerq(rq); return -1; - } - return launch_requests(rq, reviveok); /* now start the requests if we can */ + } + return launch_requests(rq, reviveok); /* now start the requests if we can */ } else /* This is a write operation. We write to all * plexes. If this is a RAID 5 plex, we must also * update the parity stripe. */ { if (vol != NULL) { vol->writes++; vol->bytes_written += bp->b_bcount; status = build_write_request(rq); /* Not all the subdisks are up */ } else { /* plex I/O */ daddr_t diskstart; diskstart = bp->b_blkno; /* start offset of transfer */ status = bre(rq, PLEXNO(bp->b_dev), &diskstart, bp->b_blkno + (bp->b_bcount / DEV_BSIZE)); /* build requests for the plex */ } if ((status > REQUEST_RECOVERED) /* can't satisfy it */ ||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */ if (status == REQUEST_DOWN) { /* not enough subdisks */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; } if ((bp->b_flags & B_DONE) == 0) biodone(bp); freerq(rq); return -1; - } - return launch_requests(rq, reviveok); /* start the requests */ + } + return launch_requests (rq, reviveok); /* start the requests */ } } /* Call the low-level strategy routines to * perform the requests in a struct request */ int launch_requests(struct request *rq, int reviveok) { struct rqgroup *rqg; int rqno; /* loop index */ struct rqelement *rqe; /* current element */ int s; /* First find out whether we're reviving, and the * request contains a conflict. If so, we hang * the request off plex->waitlist of the first * plex we find which is reviving */ if ((rq->flags & XFR_REVIVECONFLICT) /* possible revive conflict */ &&(!reviveok)) { /* and we don't want to do it now, */ struct volume *vol = &VOL[VOLNO(rq->bp->b_dev)]; struct plex *plex; int plexno; for (plexno = 0; plexno < vol->plexes; plexno++) { /* find the reviving plex */ plex = &PLEX[vol->plex[plexno]]; if (plex->state == plex_reviving) /* found it */ break; } if (plexno < vol->plexes) { /* found it? */ struct request *waitlist = plex->waitlist; /* point to the waiting list */ while (waitlist->next != NULL) /* find the end */ waitlist = waitlist->next; waitlist->next = rq; /* hook our request there */ return 0; /* and get out of here */ } else /* bad vinum, bad */ printf("vinum: can't find reviving plex for volume %s\n", vol->name); } rq->active = 0; /* nothing yet */ /* XXX This is probably due to a bug */ if (rq->rqg == NULL) { /* no request */ abortrequest(rq, EINVAL); return -1; } #if DEBUG if (debug & DEBUG_ADDRESSES) - printf("Request: %x\nWrite dev 0x%x, offset 0x%x, length %ld\n", + printf("Request: %x\n%s dev 0x%x, offset 0x%x, length %ld\n", (u_int) rq, + rq->bp->b_flags & B_READ ? "Read" : "Write", rq->bp->b_dev, rq->bp->b_blkno, rq->bp->b_bcount); /* XXX */ vinum_conf.lastrq = (int) rq; vinum_conf.lastbuf = rq->bp; + if (debug & DEBUG_LASTREQS) + logrq(loginfo_user_bpl, rq->bp, rq->bp); #endif for (rqg = rq->rqg; rqg != NULL; rqg = rqg->next) { /* through the whole request chain */ rqg->active = rqg->count; /* they're all active */ rq->active++; /* one more active request group */ for (rqno = 0; rqno < rqg->count; rqno++) { rqe = &rqg->rqe[rqno]; if (rqe->flags & XFR_BAD_SUBDISK) /* this subdisk is bad, */ rqg->active--; /* one less active request */ else { struct drive *drive = &DRIVE[rqe->driveno]; /* drive to access */ if ((rqe->b.b_flags & B_READ) == 0) rqe->b.b_vp->v_numoutput++; /* one more output going */ #if DEBUG if (debug & DEBUG_ADDRESSES) printf(" %s dev 0x%x, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n", rqe->b.b_flags & B_READ ? "Read" : "Write", rqe->b.b_dev, rqe->sdno, (u_int) (rqe->b.b_blkno - SD[rqe->sdno].driveoffset), rqe->b.b_blkno, rqe->b.b_bcount); /* XXX */ if (debug & DEBUG_NUMOUTPUT) printf(" vinumstart sd %d numoutput %ld\n", rqe->sdno, rqe->b.b_vp->v_numoutput); + if (debug & DEBUG_LASTREQS) + logrq(loginfo_rqe, rqe, rq->bp); #endif /* fire off the request */ s = splbio(); (*bdevsw[major(rqe->b.b_dev)]->d_strategy) (&rqe->b); splx(s); } /* XXX Do we need caching? Think about this more */ } } return 0; } /* define the low-level requests needed to perform a * high-level I/O operation for a specific plex 'plexno'. * * Return 0 if all subdisks involved in the request are up, 1 if some * subdisks are not up, and -1 if the request is at least partially * outside the bounds of the subdisks. * * Modify the pointer *diskstart to point to the end address. On * read, return on the first bad subdisk, so that the caller * (build_read_request) can try alternatives. * * On entry to this routine, the rqg structures are not assigned. The * assignment is performed by expandrq(). Strictly speaking, the * elements rqe->sdno of all entries should be set to -1, since 0 * (from bzero) is a valid subdisk number. We avoid this problem by * initializing the ones we use, and not looking at the others (index * >= rqg->requests). */ enum requeststatus bre(struct request *rq, int plexno, daddr_t * diskaddr, daddr_t diskend) { BROKEN_GDB; int sdno; struct sd *sd; struct rqgroup *rqg; struct buf *bp; /* user's bp */ struct plex *plex; enum requeststatus status; /* return value */ daddr_t plexoffset; /* offset of transfer in plex */ daddr_t stripebase; /* base address of stripe (1st subdisk) */ daddr_t stripeoffset; /* offset in stripe */ daddr_t blockoffset; /* offset in stripe on subdisk */ struct rqelement *rqe; /* point to this request information */ daddr_t diskstart = *diskaddr; /* remember where this transfer starts */ bp = rq->bp; /* buffer pointer */ status = REQUEST_OK; /* return value: OK until proven otherwise */ plex = &PLEX[plexno]; /* point to the plex */ switch (plex->organization) { case plex_concat: for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; if ((*diskaddr < (sd->plexoffset + sd->sectors)) /* The request starts before the end of this */ &&(diskend > sd->plexoffset)) { /* subdisk and ends after the start of this sd */ if ((sd->state != sd_up) || (plex->state != plex_up)) { enum requeststatus s; s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */ if (s) /* give up? */ return s; /* yup */ } rqg = allocrqg(rq, 1); /* space for the request */ if (rqg == NULL) { /* malloc failed */ bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; } rqg->plexno = plexno; rqe = &rqg->rqe[0]; /* point to the element */ rqe->rqg = rqg; /* group */ rqe->sdno = sd->sdno; /* put in the subdisk number */ plexoffset = max(sd->plexoffset, *diskaddr); /* start offset in plex */ rqe->sdoffset = plexoffset - sd->plexoffset; /* start offset in subdisk */ rqe->useroffset = plexoffset - diskstart; /* start offset in user buffer */ rqe->dataoffset = 0; rqe->datalen = min(diskend - *diskaddr, /* number of sectors to transfer in this sd */ sd->sectors - rqe->sdoffset); rqe->groupoffset = 0; /* no groups for concatenated plexes */ rqe->grouplen = 0; rqe->buflen = rqe->datalen; /* buffer length is data buffer length */ rqe->flags = 0; rqe->driveno = sd->driveno; *diskaddr += rqe->datalen; /* bump the address */ if (build_rq_buffer(rqe, plex)) { /* build the buffer */ deallocrqg(rqg); bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; /* can't do it */ } } if (*diskaddr > diskend) /* we're finished, */ break; /* get out of here */ } break; case plex_striped: { while (*diskaddr < diskend) { /* until we get it all sorted out */ /* The offset of the start address from * the start of the stripe */ stripeoffset = *diskaddr % (plex->stripesize * plex->subdisks); /* The plex-relative address of the * start of the stripe */ stripebase = *diskaddr - stripeoffset; /* The number of the subdisk in which * the start is located */ sdno = stripeoffset / plex->stripesize; /* The offset from the beginning of the stripe * on this subdisk */ blockoffset = stripeoffset % plex->stripesize; sd = &SD[plex->sdnos[sdno]]; /* the subdisk in question */ if ((sd->state != sd_up) || (plex->state != plex_up)) { enum requeststatus s; s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */ if (s) /* give up? */ return s; /* yup */ } rqg = allocrqg(rq, 1); /* space for the request */ if (rqg == NULL) { /* malloc failed */ bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; } rqg->plexno = plexno; rqe = &rqg->rqe[0]; /* point to the element */ rqe->rqg = rqg; rqe->sdoffset = stripebase / plex->subdisks + blockoffset; /* start offset in this subdisk */ rqe->useroffset = *diskaddr - diskstart; /* The offset of the start in the user buffer */ rqe->dataoffset = 0; rqe->datalen = min(diskend - *diskaddr, /* the amount remaining to transfer */ plex->stripesize - blockoffset); /* and the amount left in this stripe */ rqe->groupoffset = 0; /* no groups for striped plexes */ rqe->grouplen = 0; rqe->buflen = rqe->datalen; /* buffer length is data buffer length */ rqe->flags = 0; rqe->sdno = sd->sdno; /* put in the subdisk number */ rqe->driveno = sd->driveno; if (rqe->sdoffset >= sd->sectors) { /* starts beyond the end of the subdisk? */ deallocrqg(rqg); return REQUEST_EOF; } else if (rqe->sdoffset + rqe->datalen > sd->sectors) /* ends beyond the end of the subdisk? */ rqe->datalen = sd->sectors - rqe->sdoffset; /* yes, truncate */ if (build_rq_buffer(rqe, plex)) { /* build the buffer */ deallocrqg(rqg); bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; /* can't do it */ } *diskaddr += rqe->datalen; /* look at the remainder */ if (*diskaddr < diskend) { /* didn't finish the request on this stripe */ plex->multiblock++; /* count another one */ if (sdno == plex->subdisks - 1) /* last subdisk, */ plex->multistripe++; /* another stripe as well */ } } } break; default: printf("vinum: invalid plex type in bre"); } return status; } /* Build up a request structure for reading volumes. * This function is not needed for plex reads, since there's * no recovery if a plex read can't be satisified. */ enum requeststatus build_read_request(struct request *rq, /* request */ int plexindex) { /* index in the volume's plex table */ BROKEN_GDB; struct buf *bp; daddr_t startaddr; /* offset of previous part of transfer */ daddr_t diskaddr; /* offset of current part of transfer */ daddr_t diskend; /* and end offset of transfer */ int plexno; /* plex index in vinum_conf */ struct rqgroup *rqg; /* point to the request we're working on */ struct volume *vol; /* volume in question */ off_t oldstart; /* note where we started */ int recovered = 0; /* set if we recover a read */ enum requeststatus status = REQUEST_OK; bp = rq->bp; /* buffer pointer */ diskaddr = bp->b_blkno; /* start offset of transfer */ diskend = diskaddr + (bp->b_bcount / DEV_BSIZE); /* and end offset of transfer */ rqg = &rq->rqg[plexindex]; /* plex request */ vol = &VOL[rq->volplex.volno]; /* point to volume */ while (diskaddr < diskend) { /* build up request components */ startaddr = diskaddr; status = bre(rq, vol->plex[plexindex], &diskaddr, diskend); /* build up a request */ switch (status) { case REQUEST_OK: continue; case REQUEST_RECOVERED: recovered = 1; break; case REQUEST_EOF: case REQUEST_ENOMEM: return status; /* if we get here, we have either had a failure or * a RAID 5 recovery. We don't want to use the * recovery, because it's expensive, so first we * check if we have alternatives */ case REQUEST_DOWN: /* can't access the plex */ if (vol != NULL) { /* and this is volume I/O */ /* Try to satisfy the request * from another plex */ for (plexno = 0; plexno < vol->plexes; plexno++) { diskaddr = startaddr; /* start at the beginning again */ oldstart = startaddr; /* and note where that was */ if (plexno != plexindex) { /* don't try this plex again */ bre(rq, vol->plex[plexno], &diskaddr, diskend); /* try a request */ if (diskaddr > oldstart) { /* we satisfied another part */ recovered = 1; /* we recovered from the problem */ status = REQUEST_OK; /* don't complain about it */ break; } } if (plexno == (vol->plexes - 1)) /* couldn't satisfy the request */ return REQUEST_DOWN; /* failed */ } } else return REQUEST_DOWN; /* bad luck */ } if (recovered) vol->recovered_reads += recovered; /* adjust our recovery count */ } return status; } /* Build up a request structure for writes. * Return 0 if all subdisks involved in the request are up, 1 if some * subdisks are not up, and -1 if the request is at least partially * outside the bounds of the subdisks. */ enum requeststatus build_write_request(struct request *rq) { /* request */ BROKEN_GDB; struct buf *bp; daddr_t diskstart; /* offset of current part of transfer */ daddr_t diskend; /* and end offset of transfer */ int plexno; /* plex index in vinum_conf */ struct volume *vol; /* volume in question */ enum requeststatus status; bp = rq->bp; /* buffer pointer */ vol = &VOL[rq->volplex.volno]; /* point to volume */ diskend = bp->b_blkno + (bp->b_bcount / DEV_BSIZE); /* end offset of transfer */ status = REQUEST_OK; for (plexno = 0; plexno < vol->plexes; plexno++) { diskstart = bp->b_blkno; /* start offset of transfer */ status = min(status, bre(rq, /* build requests for the plex */ vol->plex[plexno], &diskstart, diskend)); } return status; } /* Fill in the struct buf part of a request element. */ enum requeststatus build_rq_buffer(struct rqelement *rqe, struct plex *plex) { BROKEN_GDB; struct sd *sd; /* point to subdisk */ struct volume *vol; struct buf *bp; struct buf *ubp; /* user (high level) buffer header */ vol = &VOL[rqe->rqg->rq->volplex.volno]; sd = &SD[rqe->sdno]; /* point to subdisk */ bp = &rqe->b; ubp = rqe->rqg->rq->bp; /* pointer to user buffer header */ /* Initialize the buf struct */ bzero(&rqe->b, sizeof(struct buf)); bp->b_proc = ubp->b_proc; /* process pointer */ bp->b_flags = ubp->b_flags & (B_NOCACHE | B_READ | B_ASYNC); /* copy these flags from user bp */ bp->b_flags |= B_CALL | B_BUSY; /* inform us when it's done */ if (plex->state == plex_reviving) bp->b_flags |= B_ORDERED; /* keep request order if we're reviving */ bp->b_iodone = complete_rqe; /* by calling us here */ bp->b_dev = DRIVE[rqe->driveno].dev; /* drive device */ bp->b_blkno = rqe->sdoffset + sd->driveoffset; /* start address */ bp->b_bcount = rqe->buflen << DEV_BSHIFT; /* number of bytes to transfer */ bp->b_resid = bp->b_bcount; /* and it's still all waiting */ bp->b_bufsize = bp->b_bcount; /* and buffer size */ bp->b_vp = DRIVE[rqe->driveno].vp; /* drive vnode */ bp->b_rcred = FSCRED; /* we have the file system credentials */ bp->b_wcred = FSCRED; /* we have the file system credentials */ if (rqe->flags & XFR_MALLOCED) { /* this operation requires a malloced buffer */ bp->b_data = Malloc(bp->b_bcount); /* get a buffer to put it in */ if (bp->b_data == NULL) { /* failed */ Debugger("XXX"); abortrequest(rqe->rqg->rq, ENOMEM); return REQUEST_ENOMEM; /* no memory */ } } else /* Point directly to user buffer data. This means * that we don't need to do anything when we have * finished the transfer */ bp->b_data = ubp->b_data + rqe->useroffset * DEV_BSIZE; return 0; } /* Abort a request: free resources and complete the * user request with the specified error */ int abortrequest(struct request *rq, int error) { struct buf *bp = rq->bp; /* user buffer */ bp->b_flags |= B_ERROR; bp->b_error = error; freerq(rq); /* free everything we're doing */ biodone(bp); return error; /* and give up */ } /* Check that our transfer will cover the * complete address space of the user request. * * Return 1 if it can, otherwise 0 */ int check_range_covered(struct request *rq) { /* XXX */ return 1; } /* Perform I/O on a subdisk */ void sdio(struct buf *bp) { int s; /* spl */ struct sd *sd; struct sdbuf *sbp; daddr_t endoffset; struct drive *drive; sd = &SD[SDNO(bp->b_dev)]; /* point to the subdisk */ drive = &DRIVE[sd->driveno]; if (drive->state != drive_up) { /* XXX until we get the states fixed */ set_sd_state(SDNO(bp->b_dev), sd_obsolete, setstate_force); bp->b_flags |= B_ERROR; bp->b_error = EIO; biodone(bp); return; } /* XXX decide which states we will really accept here. up * implies it could be involved with a plex, in which * case we don't want to dick with it */ if ((sd->state != sd_up) && (sd->state != sd_initializing) && (sd->state != sd_reborn)) { /* we can't access it */ bp->b_flags |= B_ERROR; bp->b_flags = EIO; if (bp->b_flags & B_BUSY) /* XXX why isn't this always the case? */ biodone(bp); return; } /* Get a buffer */ sbp = (struct sdbuf *) Malloc(sizeof(struct sdbuf)); if (sbp == NULL) { bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return; } bcopy(bp, &sbp->b, sizeof(struct buf)); /* start with the user's buffer */ sbp->b.b_flags |= B_CALL; /* tell us when it's done */ sbp->b.b_iodone = sdio_done; /* here */ sbp->b.b_dev = DRIVE[sd->driveno].dev; /* device */ sbp->b.b_vp = DRIVE[sd->driveno].vp; /* vnode */ sbp->b.b_blkno += sd->driveoffset; sbp->bp = bp; /* note the address of the original header */ sbp->sdno = sd->sdno; /* note for statistics */ sbp->driveno = sd->driveno; endoffset = bp->b_blkno + sbp->b.b_bcount / DEV_BSIZE; /* final sector offset */ if (endoffset > sd->sectors) { /* beyond the end */ sbp->b.b_bcount -= (endoffset - sd->sectors) * DEV_BSIZE; /* trim */ if (sbp->b.b_bcount <= 0) { /* nothing to transfer */ bp->b_resid = bp->b_bcount; /* nothing transferred */ /* XXX Grrr. This doesn't seem to work. Return * an error after all */ bp->b_flags |= B_ERROR; bp->b_error = ENOSPC; biodone(bp); Free(sbp); return; } } if ((sbp->b.b_flags & B_READ) == 0) /* write */ sbp->b.b_vp->v_numoutput++; /* one more output going */ #if DEBUG if (debug & DEBUG_ADDRESSES) printf(" %s dev 0x%x, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n", sbp->b.b_flags & B_READ ? "Read" : "Write", sbp->b.b_dev, sbp->sdno, (u_int) (sbp->b.b_blkno - SD[sbp->sdno].driveoffset), (int) sbp->b.b_blkno, sbp->b.b_bcount); /* XXX */ if (debug & DEBUG_NUMOUTPUT) printf(" vinumstart sd %d numoutput %ld\n", sbp->sdno, sbp->b.b_vp->v_numoutput); #endif s = splbio(); (*bdevsw[major(sbp->b.b_dev)]->d_strategy) (&sbp->b); splx(s); } /* Simplified version of bounds_check_with_label * Determine the size of the transfer, and make sure it is * within the boundaries of the partition. Adjust transfer * if needed, and signal errors or early completion. * * Volumes are simpler than disk slices: they only contain * one component (though we call them a, b and c to make * system utilities happy), and they always take up the * complete space of the "partition". * * I'm still not happy with this: why should the label be * protected? If it weren't so damned difficult to write * one in the first pleace (because it's protected), it wouldn't * be a problem. */ int vinum_bounds_check(struct buf *bp, struct volume *vol) { int maxsize = vol->size; /* size of the partition (sectors) */ int size = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; /* size of this request (sectors) */ /* Would this transfer overwrite the disk label? */ if (bp->b_blkno <= LABELSECTOR /* starts before or at the label */ #if LABELSECTOR != 0 && bp->b_blkno + size > LABELSECTOR /* and finishes after */ #endif && (!(vol->flags & VF_RAW)) /* and it's not raw */ &&major(bp->b_dev) == BDEV_MAJOR /* and it's the block device */ && (bp->b_flags & B_READ) == 0 /* and it's a write */ && (!vol->flags & (VF_WLABEL | VF_LABELLING))) { /* and we're not allowed to write the label */ bp->b_error = EROFS; /* read-only */ bp->b_flags |= B_ERROR; return -1; } if (size == 0) /* no transfer specified, */ return 0; /* treat as EOF */ /* beyond partition? */ if (bp->b_blkno < 0 /* negative start */ || bp->b_blkno + size > maxsize) { /* or goes beyond the end of the partition */ /* if exactly at end of disk, return an EOF */ if (bp->b_blkno == maxsize) { bp->b_resid = bp->b_bcount; return 0; } /* or truncate if part of it fits */ size = maxsize - bp->b_blkno; if (size <= 0) { /* nothing to transfer */ bp->b_error = EINVAL; bp->b_flags |= B_ERROR; return -1; } bp->b_bcount = size << DEV_BSHIFT; } bp->b_pblkno = bp->b_blkno; return 1; } /* Allocate a request group and hook * it in in the list for rq */ struct rqgroup * allocrqg(struct request *rq, int elements) { struct rqgroup *rqg; /* the one we're going to allocate */ int size = sizeof(struct rqgroup) + elements * sizeof(struct rqelement); rqg = (struct rqgroup *) Malloc(size); if (rqg != NULL) { /* malloc OK, */ if (rq->rqg) /* we already have requests */ rq->lrqg->next = rqg; /* hang it off the end */ else /* first request */ rq->rqg = rqg; /* at the start */ rq->lrqg = rqg; /* this one is the last in the list */ bzero(rqg, size); /* no old junk */ rqg->rq = rq; /* point back to the parent request */ rqg->count = elements; /* number of requests in the group */ } else Debugger("XXX"); return rqg; } /* Deallocate a request group out of a chain. We do * this by linear search: the chain is short, this * almost never happens, and currently it can only * happen to the first member of the chain. */ void deallocrqg(struct rqgroup *rqg) { struct rqgroup *rqgc = rqg->rq->rqg; /* point to the request chain */ if (rqg->rq->rqg == rqg) /* we're first in line */ rqg->rq->rqg = rqg->next; /* unhook ourselves */ else { while (rqgc->next != rqg) /* find the group */ rqgc = rqgc->next; rqgc->next = rqg->next; } Free(rqgc); } /* Character device interface */ int vinumread(dev_t dev, struct uio *uio, int ioflag) { return (physio(vinumstrategy, NULL, dev, 1, minphys, uio)); } int vinumwrite(dev_t dev, struct uio *uio, int ioflag) { return (physio(vinumstrategy, NULL, dev, 0, minphys, uio)); } diff --git a/lkm/vinum/request.h b/lkm/vinum/request.h index b4beccca9b42..6575204c765f 100644 --- a/lkm/vinum/request.h +++ b/lkm/vinum/request.h @@ -1,159 +1,191 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: request.h,v 1.10 1998/08/03 07:15:26 grog Exp grog $ */ /* Information needed to set up a transfer */ /* struct buf is surprisingly big (about 300 * bytes), and it's part of the request, so this * value is really important. Most requests * don't need more than 2 subrequests per * plex. The table is automatically extended if * this value is too small. */ #define RQELTS 2 /* default of 2 requests per transfer */ enum xferinfo { XFR_NORMAL_READ = 1, XFR_NORMAL_WRITE = 2, /* write request in normal mode */ XFR_RECOVERY_READ = 4, XFR_DEGRADED_WRITE = 8, XFR_PARITYLESS_WRITE = 0x10, XFR_NO_PARITY_STRIPE = 0x20, /* parity stripe is not available */ XFR_DATA_BLOCK = 0x40, /* data block in request */ XFR_PARITY_BLOCK = 0x80, /* parity block in request */ XFR_BAD_SUBDISK = 0x100, /* this subdisk is dead */ XFR_MALLOCED = 0x200, /* this buffer is malloced */ #if DEBUG XFR_PHASE2 = 0x800, /* documentation only: 2nd phase write */ #endif XFR_REVIVECONFLICT = 0x1000, /* possible conflict with a revive operation */ /* operations that need a parity block */ XFR_PARITYOP = (XFR_NORMAL_WRITE | XFR_RECOVERY_READ | XFR_DEGRADED_WRITE), /* operations that use the group parameters */ XFR_GROUPOP = (XFR_DEGRADED_WRITE | XFR_RECOVERY_READ), /* operations that that use the data parameters */ XFR_DATAOP = (XFR_NORMAL_READ | XFR_NORMAL_WRITE | XFR_PARITYLESS_WRITE), /* operations requiring read before write */ XFR_RBW = (XFR_NORMAL_WRITE | XFR_DEGRADED_WRITE), /* operations that need a malloced buffer */ XFR_NEEDS_MALLOC = (XFR_NORMAL_WRITE | XFR_RECOVERY_READ | XFR_DEGRADED_WRITE) }; /* Describe one low-level request, part * of a high-level request. This is an * extended struct buf buffer, and the first * element *must* be a struct buf. We pass this structure * to the I/O routines instead of a struct buf in oder * to be able to locate the high-level request when it * completes. * * All offsets and lengths are in "blocks", i.e. sectors */ struct rqelement { struct buf b; /* buf structure */ struct rqgroup *rqg; /* pointer to our group */ /* Information about the transfer */ daddr_t sdoffset; /* offset in subdisk */ int useroffset; /* offset in user buffer of normal data */ /* dataoffset and datalen refer to "individual" * data transfers (normal read, parityless write) * and also degraded write. * * groupoffset and grouplen refer to the other * "group" operations (normal write, recovery read) * Both the offsets are relative to the start of the * local buffer */ int dataoffset; /* offset in buffer of the normal data */ int groupoffset; /* offset in buffer of group data */ short datalen; /* length of normal data (sectors) */ short grouplen; /* length of group data (sectors) */ short buflen; /* total buffer length to allocate */ short flags; /* really enum xferinfo (see above) */ /* Ways to find other components */ short sdno; /* subdisk number */ short driveno; /* drive number */ }; /* A group of requests built to satisfy a certain * component of a user request */ struct rqgroup { struct rqgroup *next; /* pointer to next group */ struct request *rq; /* pointer to the request */ short count; /* number of requests in this group */ short active; /* and number active */ short plexno; /* index of plex */ int badsdno; /* index of bad subdisk or -1 */ enum xferinfo flags; /* description of transfer */ struct rqelement rqe[0]; /* and the elements of this request */ }; /* Describe one high-level request and the * work we have to do to satisfy it */ struct request { struct buf *bp; /* pointer to the high-level request */ int flags; union { int volno; /* volume index */ int plexno; /* or plex index */ } volplex; int error; /* current error indication */ short isplex; /* set if this is a plex request */ short active; /* number of subrequests still active */ struct rqgroup *rqg; /* pointer to the first group of requests */ struct rqgroup *lrqg; /* and to the first group of requests */ struct request *next; /* link of waiting requests */ }; /* Extended buffer header for subdisk I/O. Includes * a pointer to the user I/O request. */ struct sdbuf { struct buf b; /* our buffer */ struct buf *bp; /* and pointer to parent */ short driveno; /* drive index */ short sdno; /* and subdisk index */ }; /* Values returned by rqe and friends. * Be careful with these: they are in order of increasing * seriousness. Some routines check for > REQUEST_RECOVERED * to indicate a completely failed request. */ enum requeststatus { REQUEST_OK, /* request built OK */ REQUEST_RECOVERED, /* request OK, but involves RAID5 recovery */ REQUEST_EOF, /* request failed: outside plex */ REQUEST_DOWN, /* request failed: subdisk down */ REQUEST_ENOMEM /* ran out of memory */ }; + +#ifdef DEBUG +/* Trace entry for request info (DEBUG_LASTREQS) */ +enum rqinfo_type { + loginfo_unused, /* never been used */ + loginfo_user_bp, /* this is the bp when strategy is called */ + loginfo_user_bpl, /* and this is the bp at launch time */ + loginfo_rqe, /* user RQE */ + loginfo_iodone, /* iodone */ + loginfo_raid5_data, /* write RAID-5 data block */ + loginfo_raid5_parity /* write RAID-5 parity block */ +}; + +union rqinfou { /* info to pass to logrq */ + struct buf *bp; + struct rqelement *rqe; /* address of request, for correlation */ +}; + +struct rqinfo { + enum rqinfo_type type; /* kind of event */ + struct timeval timestamp; /* time it happened */ + struct buf *bp; /* point to user buffer */ + union { + struct buf b; /* yup, the *whole* buffer header */ + struct rqelement rqe; /* and the whole rqe */ + } info; +}; + +#define RQINFO_SIZE 64 /* number of info slots in buffer */ + +void logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp); +#endif diff --git a/lkm/vinum/state.c b/lkm/vinum/state.c index 2ce2ed0c29e5..928cb38765b1 100644 --- a/lkm/vinum/state.c +++ b/lkm/vinum/state.c @@ -1,755 +1,759 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: state.c,v 2.6 1998/08/19 08:04:47 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" /* Update drive state */ /* Return 1 if the state changes, otherwise 0 */ int set_drive_state(int driveno, enum drivestate state, int flags) { struct drive *drive = &DRIVE[driveno]; int oldstate = drive->state; int sdno; if (drive->state == drive_unallocated) /* no drive to do anything with, */ return 0; if (state != oldstate) { /* don't change it if it's not different */ if (state == drive_down) { /* the drive's going down */ if (flags || (drive->opencount == 0)) { /* we can do it */ close_drive(drive); drive->state = state; printf("vinum: drive %s is %s\n", drive->label.name, drive_state(drive->state)); } else return 0; /* don't do it */ } drive->state = state; /* set the state */ if (((drive->state == drive_up) || ((drive->state == drive_coming_up))) && (drive->vp == NULL)) /* should be open, but we're not */ init_drive(drive); /* which changes the state again */ if ((state != oldstate) /* state has changed */ &&((flags & setstate_norecurse) == 0)) { /* and we want to recurse, */ for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { /* find this drive's subdisks */ if (SD[sdno].driveno == driveno) /* belongs to this drive */ set_sd_state(sdno, sd_down, setstate_force | setstate_recursing); /* take it down */ } save_config(); /* and save the updated configuration */ return 1; } } return 0; } /* Try to set the subdisk state. Return 1 if state changed to * what we wanted, -1 if it changed to something else, and 0 * if no change. * * This routine is called both from the user (up, down states * only) and internally. */ int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags) { struct sd *sd = &SD[sdno]; int oldstate = sd->state; int status = 1; /* status to return */ if (state == oldstate) return 0; /* no change */ if (sd->state == sd_unallocated) /* no subdisk to do anything with, */ return 0; if (sd->driveoffset < 0) { /* not allocated space */ sd->state = sd_down; if (state != sd_down) return -1; } else { /* space allocated */ switch (state) { case sd_down: if ((!flags & setstate_force) /* but gently */ &&(sd->plexno >= 0)) /* and we're attached to a plex, */ return 0; /* don't do it */ break; case sd_up: if (DRIVE[sd->driveno].state != drive_up) /* can't bring the sd up if the drive isn't, */ return 0; /* not even by force */ switch (sd->state) { case sd_obsolete: case sd_down: /* been down, no data lost */ if ((sd->plexno) /* we're associated with a plex */ &&(((PLEX[sd->plexno].state < plex_firstup) /* and it's not up */ ||(PLEX[sd->plexno].subdisks > 1)))) /* or it's the only one */ break; /* XXX Get this right: make sure that other plexes in * the volume cover this address space, otherwise * we make this one sd_up */ sd->state = sd_reborn; /* here it is again */ printf("vinum: subdisk %s is %s, not %s\n", sd->name, sd_state(sd->state), sd_state(state)); status = -1; break; case sd_init: /* brand new */ if (flags & setstate_configuring) /* we're doing this while configuring */ break; sd->state = sd_empty; /* nothing in it */ printf("vinum: subdisk %s is %s, not %s\n", sd->name, sd_state(sd->state), sd_state(state)); status = -1; break; case sd_initializing: break; /* go on and do it */ case sd_empty: if ((sd->plexno) /* we're associated with a plex */ &&(((PLEX[sd->plexno].state < plex_firstup) /* and it's not up */ ||(PLEX[sd->plexno].subdisks > 1)))) /* or it's the only one */ break; return 0; /* can't do it */ default: /* can't do it */ /* There's no way to bring subdisks up directly from * other states. First they need to be initialized * or revived */ return 0; } break; default: /* other ones, only internal with force */ if (flags & setstate_force == 0) /* no force? What's this? */ return 0; /* don't do it */ } } sd->state = state; printf("vinum: subdisk %s is %s\n", sd->name, sd_state(sd->state)); if ((flags & setstate_norecurse) == 0) set_plex_state(sd->plexno, plex_up, setstate_recursing); /* update plex state */ - if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ - save_config(); + if ((flags & (setstate_configuring | setstate_recursing)) == 0) { /* save config now */ + if (setstate_noupdate) /* we can't update now, */ + vinum_conf.flags |= VF_DIRTYCONFIG; /* wait until later */ + else + save_config(); + } return status; } /* Called from request routines when they find * a subdisk which is not kosher. Decide whether * it warrants changing the state. Return * REQUEST_DOWN if we can't use the subdisk, * REQUEST_OK if we can. */ enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend) { struct plex *plex = &PLEX[sd->plexno]; int writeop = (rq->bp->b_flags & B_READ) == 0; /* note if we're writing */ /* first, see if the plex wants to be accessed */ switch (plex->state) { case plex_reviving: /* When writing, we'll write anything that starts * up to the current revive pointer, but we'll * only accept a read which finishes before the * current revive pointer. */ if ((writeop && (diskaddr > plex->revived)) /* write starts after current revive pointer */ ||((!writeop) && (diskend >= plex->revived))) { /* or read ends after current revive pointer */ if (writeop) { /* writing to a consistent down disk */ if (DRIVE[sd->driveno].state == drive_up) set_sd_state(sd->sdno, sd_stale, setstate_force); /* it's not consistent now */ else set_sd_state(sd->sdno, sd_obsolete, setstate_force); /* it's not consistent now */ } return REQUEST_DOWN; /* that part of the plex is still down */ } else if (diskend >= plex->revived) /* write finishes beyond revive pointer */ rq->flags |= XFR_REVIVECONFLICT; /* note a potential conflict */ /* FALLTHROUGH */ case plex_up: case plex_degraded: case plex_flaky: /* We can access the plex: let's see * how the subdisk feels */ switch (sd->state) { case sd_up: return REQUEST_OK; case sd_reborn: if (writeop) return REQUEST_OK; /* always write to a reborn disk */ /* Handle the mapping. We don't want to reject * a read request to a reborn subdisk if that's * all we have. XXX */ return REQUEST_DOWN; case sd_down: case sd_crashed: if (writeop) { /* writing to a consistent down disk */ if (DRIVE[sd->driveno].state == drive_up) set_sd_state(sd->sdno, sd_stale, setstate_force); /* it's not consistent now */ else set_sd_state(sd->sdno, sd_obsolete, setstate_force); /* it's not consistent now */ } return REQUEST_DOWN; /* and it's down one way or another */ default: return REQUEST_DOWN; } default: return REQUEST_DOWN; } } void add_defective_region(struct plex *plex, off_t offset, size_t length) { /* XXX get this ordered, and coalesce regions if necessary */ if (++plex->defective_regions > plex->defective_region_count) EXPAND(plex->defective_region, struct plexregion, plex->defective_region_count, PLEX_REGION_TABLE_SIZE); plex->defective_region[plex->defective_regions - 1].offset = offset; plex->defective_region[plex->defective_regions - 1].length = length; } void add_unmapped_region(struct plex *plex, off_t offset, size_t length) { if (++plex->unmapped_regions > plex->unmapped_region_count) EXPAND(plex->unmapped_region, struct plexregion, plex->unmapped_region_count, PLEX_REGION_TABLE_SIZE); plex->unmapped_region[plex->unmapped_regions - 1].offset = offset; plex->unmapped_region[plex->unmapped_regions - 1].length = length; } /* Rebuild a plex free list and set state if * we have a configuration error */ void rebuild_plex_unmappedlist(struct plex *plex) { int sdno; struct sd *sd; int lastsdend = 0; /* end offset of last subdisk */ if (plex->unmapped_region != NULL) { /* we're going to rebuild it */ Free(plex->unmapped_region); plex->unmapped_region = NULL; plex->unmapped_regions = 0; plex->unmapped_region_count = 0; } if (plex->defective_region != NULL) { Free(plex->defective_region); plex->defective_region = NULL; plex->defective_regions = 0; plex->defective_region_count = 0; } for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; if (sd->plexoffset < lastsdend) { /* overlap */ printf("vinum: Plex %s, subdisk %s overlaps previous\n", plex->name, sd->name); set_plex_state(plex->plexno, plex_down, setstate_force); /* don't allow that */ } else if (sd->plexoffset > lastsdend) /* gap */ add_unmapped_region(plex, lastsdend, sd->plexoffset - lastsdend); else if (sd->state < sd_reborn) /* this part defective */ add_defective_region(plex, sd->plexoffset, sd->sectors); lastsdend = sd->plexoffset + sd->sectors; } } /* return a state map for the subdisks of a plex */ enum sdstates sdstatemap(struct plex *plex, int *sddowncount) { int sdno; enum sdstates statemap = 0; /* note the states we find */ *sddowncount = 0; /* no subdisks down yet */ for (sdno = 0; sdno < plex->subdisks; sdno++) { struct sd *sd = &SD[plex->sdnos[sdno]]; /* point to the subdisk */ switch (sd->state) { case sd_empty: statemap |= sd_emptystate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_init: statemap |= sd_initstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_down: statemap |= sd_downstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_crashed: statemap |= sd_crashedstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_obsolete: statemap |= sd_obsolete; (*sddowncount)++; /* another unusable subdisk */ break; case sd_stale: statemap |= sd_stalestate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_reborn: statemap |= sd_rebornstate; break; case sd_up: statemap |= sd_upstate; break; default: statemap |= sd_otherstate; break; } } return statemap; } /* determine the state of the volume relative to this plex */ enum volplexstate vpstate(struct plex *plex) { struct volume *vol; enum volplexstate state = volplex_onlyusdown; /* state to return */ int plexno; if (plex->volno < 0) /* not associated with a volume */ return volplex_onlyusdown; /* assume the worst */ vol = &VOL[plex->volno]; /* point to our volume */ for (plexno = 0; plexno < vol->plexes; plexno++) { if (&PLEX[vol->plex[plexno]] == plex) { /* us */ if (PLEX[vol->plex[plexno]].state == plex_up) /* are we up? */ state |= volplex_onlyus; /* yes */ } else { if (PLEX[vol->plex[plexno]].state == plex_up) /* not us */ state |= volplex_otherup; /* and when they were up, they were up */ else state |= volplex_alldown; /* and when they were down, they were down */ } } return state; /* and when they were only halfway up */ } /* they were neither up nor down */ /* Check if all bits b are set in a */ int allset(int a, int b); int allset(int a, int b) { return (a & b) == b; } /* Update the state of a plex dependent on its subdisks. * Also rebuild the unmapped_region and defective_region table */ int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags) { int sddowncount = 0; /* number of down subdisks */ struct plex *plex = &PLEX[plexno]; /* point to our plex */ enum plexstate oldstate = plex->state; enum volplexstate vps = vpstate(plex); /* how do we compare with the other plexes? */ enum sdstates statemap = sdstatemap(plex, &sddowncount); /* get a map of the subdisk states */ if ((flags & setstate_force) && (oldstate == state)) /* we're there already, */ return 0; /* no change */ if (plex->state == plex_unallocated) /* no plex to do anything with, */ return 0; switch (state) { case plex_up: if ((plex->state == plex_initializing) /* we're initializing */ &&(statemap != sd_upstate)) /* but SDs aren't up yet */ return 0; /* do nothing */ /* We don't really care what our state was before * if we want to come up. We rely entirely on the * state of our subdisks and our volume */ switch (vps) { case volplex_onlyusdown: case volplex_alldown: /* another plex is down, and so are we */ if (statemap == sd_upstate) { /* all subdisks ready for action */ if ((plex->state == plex_init) /* we're brand spanking new */ &&(VOL[plex->volno].flags & VF_CONFIG_SETUPSTATE)) { /* and we consider that up */ /* Conceptually, an empty plex does not contain valid data, * but normally we'll see this state when we have just * created a plex, and it's either consistent from earlier, * or we don't care about the previous contents (we're going * to create a file system or use it for swap). * * We need to do this in one swell foop: on the next call * we will no longer be just empty. * * We'll still come back to this function for the remaining * plexes in the volume. They'll be up already, so that * doesn't change anything, but it's not worth the additional * code to stop doing it. */ struct volume *vol = &VOL[plex->volno]; int plexno; for (plexno = 0; plexno < vol->plexes; plexno++) PLEX[vol->plex[plexno]].state = plex_up; } plex->state = plex_up; /* bring up up, anyway */ } else plex->state = plex_down; break; case volplex_onlyusup: /* only we are up: others are down */ case volplex_onlyus: /* we're up and alone */ if ((statemap == sd_upstate) /* subdisks all up */ ||(statemap == sd_emptystate)) /* or all empty */ plex->state = plex_up; /* go for it */ else if ((statemap & (sd_upstate | sd_reborn)) == statemap) /* all up or reborn, */ plex->state = plex_flaky; else if (statemap & (sd_upstate | sd_reborn)) /* some up or reborn, */ plex->state = plex_degraded; /* so far no corruption */ else plex->state = plex_faulty; break; case volplex_otherup: /* another plex is up */ case volplex_otherupdown: /* other plexes are up and down */ if ((statemap == sd_upstate) /* subdisks all up */ ||(statemap == sd_emptystate) /* or all empty */ ) { /* Is the data in all subdisks valid? */ if (statemap == statemap & (sd_downstate | sd_rebornstate | sd_upstate)) break; /* yes, we can bring the plex up */ plex->state = plex_reviving; /* we need reviving */ return EAGAIN; } else plex->state = plex_faulty; /* still in error */ break; case volplex_allup: /* all plexes are up */ case volplex_someup: if ((statemap & (sd_upstate | sd_reborn)) == statemap) /* all up or reborn, */ break; /* no change */ else plex->state = plex_degraded; /* we're not all there */ } if (plex->state != oldstate) break; return 0; /* no change */ case plex_down: /* want to take it down */ if (((vps == volplex_onlyus) /* we're the only one up */ ||(vps == volplex_onlyusup)) /* we're the only one up */ &&(!(flags & setstate_force))) /* and we don't want to use force */ return 0; /* can't do it */ plex->state = state; /* do it */ break; /* This is only requested by the driver. * Trust ourselves */ case plex_faulty: plex->state = state; /* do it */ break; case plex_initializing: /* XXX consider what safeguards we need here */ if ((flags & setstate_force) == 0) return 0; plex->state = state; /* do it */ break; /* What's this? */ default: return 0; } printf("vinum: plex %s is %s\n", plex->name, plex_state(plex->state)); /* Now see what we have left, and whether * we're taking the volume down */ if (plex->volno >= 0) { /* we have a volume */ struct volume *vol = &VOL[plex->volno]; vps = vpstate(plex); /* get our combined state again */ if ((flags & setstate_norecurse) == 0) { /* we can recurse */ if ((vol->state == volume_up) && (vps == volplex_alldown)) /* and we're all down */ set_volume_state(plex->volno, volume_down, setstate_recursing); /* take our volume down */ else if ((vol->state == volume_down) && (vps & (volplex_otherup | volplex_onlyusup))) /* and at least one is up */ set_volume_state(plex->volno, volume_up, setstate_recursing); /* bring our volume up */ } } if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } /* Update the state of a plex dependent on its plexes. * Also rebuild the unmapped_region and defective_region table */ int set_volume_state(int volno, enum volumestate state, enum setstateflags flags) { int plexno; enum plexstates { plex_downstate = 1, /* found a plex which is down */ plex_degradedstate = 2, /* found a plex which is halfway up */ plex_upstate = 4 /* found a plex which is completely up */ }; int plexstatemap = 0; /* note the states we find */ struct volume *vol = &VOL[volno]; /* point to our volume */ if (vol->state == state) /* we're there already */ return 0; /* no change */ if (vol->state == volume_unallocated) /* no volume to do anything with, */ return 0; for (plexno = 0; plexno < vol->plexes; plexno++) { struct plex *plex = &PLEX[vol->plex[plexno]]; /* point to the plex */ switch (plex->state) { case plex_degraded: case plex_flaky: case plex_reviving: plexstatemap |= plex_degradedstate; break; case plex_up: plexstatemap |= plex_upstate; break; default: plexstatemap |= plex_downstate; break; } } if (state == volume_up) { /* want to come up */ if (plexstatemap & plex_upstate) { /* we have a plex which is completely up */ vol->state = volume_up; /* did it */ printf("vinum: volume %s is %s\n", vol->name, volume_state(vol->state)); if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } /* Here we should check whether we have enough * coverage for the complete volume. Writeme XXX */ } else if (state == volume_down) { /* want to go down */ if ((vol->opencount == 0) /* not open */ ||(flags & setstate_force != 0)) { /* or we're forcing */ vol->state = volume_down; printf("vinum: volume %s is %s\n", vol->name, volume_state(vol->state)); if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } } return 0; /* no change */ } /* Start an object, in other words do what we can to get it up. * This is called from vinumioctl (VINUMSTART). * Return error indications via ioctl_reply */ void start_object(struct vinum_ioctl_msg *data) { int status; int realstatus; /* what we really have */ int objindex = data->index; /* data gets overwritten */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */ switch (data->type) { case drive_object: status = set_drive_state(objindex, drive_up, setstate_none); realstatus = DRIVE[objindex].state == drive_up; /* set status on whether we really did it */ break; case sd_object: status = set_sd_state(objindex, sd_up, setstate_none); /* set state */ realstatus = SD[objindex].state == sd_up; /* set status on whether we really did it */ break; case plex_object: if (PLEX[objindex].state == plex_reviving) { /* reviving, */ ioctl_reply->error = revive_block(objindex); /* revive another block */ ioctl_reply->msg[0] = '\0'; /* no comment */ return; } status = set_plex_state(objindex, plex_up, setstate_none); realstatus = PLEX[objindex].state == plex_up; /* set status on whether we really did it */ break; case volume_object: status = set_volume_state(objindex, volume_up, setstate_none); realstatus = VOL[objindex].state == volume_up; /* set status on whether we really did it */ break; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); return; } /* There's no point in saying anything here: * the userland program does it better */ ioctl_reply->msg[0] = '\0'; if (realstatus == 0) /* couldn't do it */ ioctl_reply->error = EINVAL; else ioctl_reply->error = 0; } /* Stop an object, in other words do what we can to get it down * This is called from vinumioctl (VINUMSTOP). * Return error indications via ioctl_reply. */ void stop_object(struct vinum_ioctl_msg *data) { int status = 1; int objindex = data->index; /* save the number from change */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */ switch (data->type) { case drive_object: status = set_drive_state(objindex, drive_down, data->force); break; case sd_object: status = set_sd_state(objindex, sd_down, data->force); break; case plex_object: status = set_plex_state(objindex, plex_down, data->force); break; case volume_object: status = set_volume_state(objindex, volume_down, data->force); break; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); return; } ioctl_reply->msg[0] = '\0'; if (status == 0) /* couldn't do it */ ioctl_reply->error = EINVAL; else ioctl_reply->error = 0; } /* VINUM_SETSTATE ioctl: set an object state * msg is the message passed by the user */ void setstate(struct vinum_ioctl_msg *msg) { int sdno; struct sd *sd; struct plex *plex; struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) msg; /* format for returning replies */ switch (msg->state) { case object_down: stop_object(msg); break; case object_initializing: switch (msg->type) { case sd_object: sd = &SD[msg->index]; if ((msg->index >= vinum_conf.subdisks_used) || (sd->state == sd_unallocated)) { sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index); ioctl_reply->error = EFAULT; return; } set_sd_state(msg->index, sd_initializing, msg->force); if (sd->state != sd_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; } else ioctl_reply->error = 0; break; case plex_object: plex = &PLEX[msg->index]; if ((msg->index >= vinum_conf.plexes_used) || (plex->state == plex_unallocated)) { sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index); ioctl_reply->error = EFAULT; return; } set_plex_state(msg->index, plex_initializing, msg->force); if (plex->state != plex_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; } else { ioctl_reply->error = 0; for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; set_sd_state(plex->sdnos[sdno], sd_initializing, msg->force); if (sd->state != sd_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; break; } } } break; default: strcpy(ioctl_reply->msg, "Invalid object"); ioctl_reply->error = EINVAL; } break; case object_up: start_object(msg); } } diff --git a/lkm/vinum/vinumext.h b/lkm/vinum/vinumext.h index 4b7d5a01d642..3b639180f17a 100644 --- a/lkm/vinum/vinumext.h +++ b/lkm/vinum/vinumext.h @@ -1,214 +1,204 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumext.h,v 1.14 1998/08/11 00:03:57 grog Exp grog $ + * $Id: vinumext.h,v 1.15 1998/09/29 05:17:56 grog Exp grog $ */ /* vinumext.h: external definitions */ extern struct _vinum_conf vinum_conf; /* configuration information */ #ifdef DEBUG extern debug; /* debug flags */ #endif #define CHECKALLOC(ptr, msg) \ if (ptr == NULL) \ { \ printf (msg); \ longjmp (command_fail, -1); \ } #ifndef KERNEL struct vnode; struct proc; #endif #ifdef KERNEL int give_sd_to_plex(int plexno, int sdno); int give_plex_to_volume(int volno, int plexno); int check_drive(char *); enum drive_label_info read_drive_label(struct drive *drive); int parse_config(char *, struct keywordset *); int parse_user_config(char *cptr, struct keywordset *keyset); u_int64_t sizespec(char *spec); int volume_index(struct volume *volume); int plex_index(struct plex *plex); int sd_index(struct sd *sd); int drive_index(struct drive *drive); int my_plex(int volno, int plexno); int my_sd(int plexno, int sdno); int get_empty_drive(void); int find_drive(const char *name, int create); int find_drive_by_dev(const char *devname, int create); int get_empty_sd(void); int find_subdisk(const char *name, int create); void free_sd(int sdno); void free_volume(int volno); int get_empty_plex(void); int find_plex(const char *name, int create); void free_plex(int plexno); int get_empty_volume(void); int find_volume(const char *name, int create); void config_subdisk(void); void config_plex(void); void config_volume(void); void config_drive(void); void updateconfig(int); void update_sd_config(int sdno, int kernelstate); void update_plex_config(int plexno, int kernelstate); void update_volume_config(int volno, int kernelstate); void update_config(void); void drive_io_done(struct buf *); int save_config(void); void write_config(char *, int); int start_config(void); void finish_config(int); void remove(struct vinum_ioctl_msg *msg); void remove_drive_entry(int driveno, int force, int recurse); void remove_sd_entry(int sdno, int force, int recurse); void remove_plex_entry(int plexno, int force, int recurse); void remove_volume_entry(int volno, int force, int recurse); void checkernel(char *); int open_drive(struct drive *, struct proc *); void close_drive(struct drive *drive); int driveio(struct drive *, void *, size_t, off_t, int); /* #define read_drive(a, b, c, d) driveio (a, b, c, d, B_READ) #define write_drive(a, b, c, d) driveio (a, b, c, d, B_WRITE) */ int set_drive_parms(struct drive *drive); int init_drive(struct drive *); /* void throw_rude_remark (int, struct _ioctl_reply *, char *, ...); XXX */ void throw_rude_remark(int, char *,...); int read_drive(struct drive *drive, void *buf, size_t length, off_t offset); int write_drive(struct drive *drive, void *buf, size_t length, off_t offset); void format_config(char *config, int len); void checkkernel(char *op); void free_drive(struct drive *drive); void down_drive(struct drive *drive); void remove_drive(int driveno); /* I/O */ d_open_t vinumopen; d_close_t vinumclose; d_strategy_t vinumstrategy; d_ioctl_t vinumioctl; d_dump_t vinumdump; d_psize_t vinumsize; d_read_t vinumread; d_write_t vinumwrite; int vinumstart(struct buf *bp, int reviveok); int launch_requests(struct request *rq, int reviveok); /* XXX Do we need this? */ int vinumpart(dev_t); -/* Memory allocation */ +#ifdef DEBUG +/* Memory allocation and request tracing */ void vinum_meminfo(caddr_t data); int vinum_mallocinfo(caddr_t data); +int vinum_rqinfo(caddr_t data); +#endif void expand_table(void **, int, int); void add_defective_region(struct plex *plex, off_t offset, size_t length); void add_unmapped_region(struct plex *plex, off_t offset, size_t length); void rebuild_plex_unmappedlist(struct plex *plex); struct request; struct rqgroup *allocrqg(struct request *rq, int elements); void deallocrqg(struct rqgroup *rqg); /* State transitions */ int set_drive_state(int driveno, enum drivestate state, int force); int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags); enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend); int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags); int set_volume_state(int volumeno, enum volumestate state, enum setstateflags flags); void get_volume_label(struct volume *vol, struct disklabel *lp); int write_volume_label(int); void start_object(struct vinum_ioctl_msg *); void stop_object(struct vinum_ioctl_msg *); void setstate(struct vinum_ioctl_msg *msg); void vinum_label(int); int vinum_writedisklabel(struct volume *, struct disklabel *); int initsd(int); int restart_plex(int plexno); int revive_block(int plexno); /* Auxiliary functions */ enum sdstates sdstatemap(struct plex *plex, int *sddowncount); enum volplexstate vpstate(struct plex *plex); #endif enum keyword get_keyword(char *, struct keywordset *); void listconfig(void); char *drive_state(enum drivestate); char *volume_state(enum volumestate); char *plex_state(enum plexstate); char *plex_org(enum plexorg); char *sd_state(enum sdstate); enum drivestate DriveState(char *text); enum sdstate SdState(char *text); enum plexstate PlexState(char *text); enum volumestate VolState(char *text); struct drive *validdrive(int driveno, struct _ioctl_reply *); struct sd *validsd(int sdno, struct _ioctl_reply *); struct plex *validplex(int plexno, struct _ioctl_reply *); struct volume *validvol(int volno, struct _ioctl_reply *); int tokenize(char *, char *[]); void resetstats(struct vinum_ioctl_msg *msg); /* Locking */ int lockvol(struct volume *vol); void unlockvol(struct volume *vol); int lockplex(struct plex *plex); void unlockplex(struct plex *plex); int lockrange(struct plex *plex, off_t first, off_t last); void unlockrange(struct plex *plex, off_t first, off_t last); int lock_config(void); void unlock_config(void); - -#ifdef DEBUG -#define expandrq(prq) \ -{ \ - expand_table ((void **) &prq->rqe, \ - prq->requests * sizeof (struct rqelement), \ - (prq->requests + RQELTS) * sizeof (struct rqelement) ); \ - bzero (&prq->rqe [prq->requests], RQELTS * sizeof (struct rqelement)); \ - prq->rqcount += RQELTS; \ - } -#else -void expandrq(struct plexrq *); -#endif diff --git a/lkm/vinum/vinumio.h b/lkm/vinum/vinumio.h index be79528a6db8..b99bd4217846 100644 --- a/lkm/vinum/vinumio.h +++ b/lkm/vinum/vinumio.h @@ -1,132 +1,141 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: vinumio.h,v 1.10 1998/08/10 05:46:19 grog Exp grog $ */ +#ifdef DEBUG +#define MAX_IOCTL_REPLY 4096 +#else #define MAX_IOCTL_REPLY 256 +#endif + #define L 'F' /* ID letter of our ioctls */ /* VINUM_CREATE returns a buffer of this kind */ struct _ioctl_reply { int error; char msg[MAX_IOCTL_REPLY]; }; /* ioctl requests */ #define BUFSIZE 1024 /* size of buffer, including continuations */ #define VINUM_CREATE _IOC(IOC_IN | IOC_OUT, L, 64, BUFSIZE) /* configure vinum */ #define VINUM_GETCONFIG _IOR(L, 65, struct _vinum_conf) /* get global config */ #define VINUM_DRIVECONFIG _IOWR(L, 66, struct drive) /* get drive config */ #define VINUM_SDCONFIG _IOWR(L, 67, struct sd) /* get subdisk config */ #define VINUM_PLEXCONFIG _IOWR(L, 68, struct plex) /* get plex config */ #define VINUM_VOLCONFIG _IOWR(L, 69, struct volume) /* get volume config */ #define VINUM_PLEXSDCONFIG _IOWR(L, 70, struct sd) /* get sd config for plex (plex, sdno) */ #define VINUM_GETFREELIST _IOWR(L, 71, struct drive_freelist) /* get freelist element (drive, fe) */ #define VINUM_SAVECONFIG _IOC(0, L, 72, 0) /* release locks, update, write config to disk */ #define VINUM_RESETCONFIG _IOC(0, L, 73, 0) /* trash config on disk */ #define VINUM_INIT _IOC(0, L, 74, 0) /* read config from disk */ #ifdef DEBUG struct debuginfo { int changeit; int param; }; #define VINUM_DEBUG _IOWR(L, 75, struct debuginfo) /* call the debugger from ioctl () */ #endif enum objecttype { drive_object, sd_object, plex_object, volume_object, invalid_object }; /* Start an object. Pass two integers: * msg [0] index in vinum_conf. * msg [1] type of object (see below) * * Return ioctl_reply */ #define VINUM_SETSTATE _IOC(IOC_IN | IOC_OUT, L, 76, MAX_IOCTL_REPLY) /* start an object */ /* The state to set with VINUM_SETSTATE. Since * each object has a different set of states, we * need to translate later */ enum objectstate { object_down, object_initializing, object_up }; /* This structure is used for modifying objects * (VINUM_SETSTATE, VINUM_REMOVE, VINUM_RESETSTATS, VINUM_ATTACH, * VINUM_DETACH, VINUM_REPLACE */ struct vinum_ioctl_msg { int index; enum objecttype type; enum objectstate state; /* state to set (VINUM_SETSTATE) */ int force; /* do it even if it doesn't make sense */ int recurse; /* recurse (VINUM_REMOVE) */ int otherobject; /* superordinate object (attach), * replacement object (replace) */ int rename; /* rename object (attach) */ int64_t offset; /* offset of subdisk (for attach) */ }; #define VINUM_RELEASECONFIG _IOC(0, L, 77, 0) /* release locks and write config to disk */ #define VINUM_STARTCONFIG _IOC(0, L, 78, 0) /* start a configuration operation */ #define VINUM_MEMINFO _IOR(L, 79, struct meminfo) /* get memory usage summary */ #define VINUM_MALLOCINFO _IOWR(L, 80, struct mc) /* get specific malloc information [i] */ #define VINUM_LABEL _IOC(IOC_IN | IOC_OUT, L, 81, MAX_IOCTL_REPLY) /* label a volume */ #define VINUM_INITSD _IOW(L, 82, int) /* initialize a subdisk */ #define VINUM_REMOVE _IOC(IOC_IN | IOC_OUT, L, 83, MAX_IOCTL_REPLY) /* remove an object */ #define VINUM_GETUNMAPPED _IOWR(L, 84, struct plexregion) /* get unmapped element (plex, re) */ #define VINUM_GETDEFECTIVE _IOWR(L, 85, struct plexregion) /* get defective element (plex, re) */ #define VINUM_RESETSTATS _IOC(IOC_IN | IOC_OUT, L, 86, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_ATTACH _IOC(IOC_IN | IOC_OUT, L, 87, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_DETACH _IOC(IOC_IN | IOC_OUT, L, 88, MAX_IOCTL_REPLY) /* reset object stats */ struct vinum_rename_msg { int index; int recurse; /* rename subordinate objects too */ enum objecttype type; char newname[MAXNAME]; /* new name to give to object */ }; #define VINUM_RENAME _IOC(IOC_IN | IOC_OUT, L, 89, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_REPLACE _IOC(IOC_IN | IOC_OUT, L, 90, MAX_IOCTL_REPLY) /* reset object stats */ + +#ifdef DEBUG +#define VINUM_RQINFO _IOWR(L, 91, struct rqinfo) /* get request info [i] from trace buffer */ +#endif diff --git a/lkm/vinum/vinumioctl.c b/lkm/vinum/vinumioctl.c index 6dbe3c6bf4d6..fd91f79a418f 100644 --- a/lkm/vinum/vinumioctl.c +++ b/lkm/vinum/vinumioctl.c @@ -1,787 +1,795 @@ /* XXX replace all the checks on object validity with * calls to valid */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumioctl.c,v 1.1 1998/08/14 08:46:10 grog Exp grog $ + * $Id: vinumioctl.c,v 1.3 1998/09/29 05:26:37 grog Exp grog $ */ #define STATIC /* nothing while we're testing XXX */ #define REALLYKERNEL #include "vinumhdr.h" #include "sys/sysproto.h" /* for sync(2) */ #ifdef DEBUG #include +#include "request.h" #endif jmp_buf command_fail; /* return on a failed command */ #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ int setjmp(jmp_buf); void longjmp(jmp_buf, int); #endif /* pointer to ioctl p parameter, to save passing it around */ struct proc *myproc; int vinum_inactive(void); void free_vinum(int); void attachobject(struct vinum_ioctl_msg *); void detachobject(struct vinum_ioctl_msg *); void renameobject(struct vinum_rename_msg *); void replaceobject(struct vinum_ioctl_msg *); /* ioctl routine */ int vinumioctl(dev_t dev, #if __FreeBSD__ >= 3 u_long cmd, #else int cmd, #endif caddr_t data, int flag, struct proc *p) { BROKEN_GDB; unsigned int objno; int error = 0; struct volume *vol; unsigned int index; /* for transferring config info */ unsigned int sdno; /* for transferring config info */ int fe; /* free list element number */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* struct to return */ struct devcode *device = (struct devcode *) &dev; /* First, decide what we're looking at */ switch (device->type) { case VINUM_SUPERDEV_TYPE: myproc = p; /* save pointer to process */ ioctl_reply = (struct _ioctl_reply *) data; /* save the address to reply to */ error = setjmp(command_fail); /* come back here on error */ if (error) /* bombed out */ return 0; /* the reply will contain meaningful info */ switch (cmd) { - /* XXX #ifdef DEBUG */ +#ifdef DEBUG case VINUM_DEBUG: - boothowto |= RB_GDB; /* serial debug line */ if (((struct debuginfo *) data)->changeit) /* change debug settings */ debug = (((struct debuginfo *) data)->param); - else + else { + if (debug & DEBUG_REMOTEGDB) + boothowto |= RB_GDB; /* serial debug line */ + else + boothowto &= ~RB_GDB; /* local ddb */ Debugger("vinum debug"); + } ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; - /* XXX #endif */ +#endif case VINUM_CREATE: /* create a vinum object */ error = lock_config(); /* get the config for us alone */ if (error) /* can't do it, */ return error; /* give up */ error = setjmp(command_fail); /* come back here on error */ if (error == 0) { /* first time, */ parse_user_config((char *) data, &keyword_set); /* update the config */ ioctl_reply->error = 0; /* no error if we make it here */ } else if (ioctl_reply->error == 0) { /* longjmp, but no error status */ ioctl_reply->error = EINVAL; /* note that something's up */ ioctl_reply->msg[0] = '\0'; /* no message? */ } unlock_config(); return 0; /* must be 0 to return the real error info */ case VINUM_GETCONFIG: /* get the configuration information */ bcopy(&vinum_conf, data, sizeof(vinum_conf)); return 0; /* start configuring the subsystem */ case VINUM_STARTCONFIG: return start_config(); /* just lock it */ /* Move the individual parts of the config to user space. * Specify the index of the object in the first word of data, * and return the object there */ case VINUM_DRIVECONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.drives_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&DRIVE[index], data, sizeof(struct drive)); /* copy the config item out */ return 0; case VINUM_SDCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.subdisks_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&SD[index], data, sizeof(struct sd)); /* copy the config item out */ return 0; case VINUM_PLEXCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.plexes_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&PLEX[index], data, sizeof(struct plex)); /* copy the config item out */ return 0; case VINUM_VOLCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.volumes_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&VOL[index], data, sizeof(struct volume)); /* copy the config item out */ return 0; case VINUM_PLEXSDCONFIG: index = *(int *) data; /* get the plex index */ sdno = ((int *) data)[1]; /* and the sd index */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(sdno >= PLEX[index].subdisks)) /* or it doesn't have this many subdisks */ return EFAULT; /* bang */ bcopy(&SD[PLEX[index].sdnos[sdno]], /* copy the config item out */ data, sizeof(struct sd)); return 0; case VINUM_SAVECONFIG: if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */ finish_config(1); /* finish the configuration and update it */ error = save_config(); /* save configuration to disk */ } else error = EINVAL; /* queue up for this one, please */ return error; case VINUM_RELEASECONFIG: /* release the config */ if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */ finish_config(0); /* finish the configuration, don't change it */ error = save_config(); /* save configuration to disk */ } else error = EINVAL; /* release what config? */ return error; case VINUM_INIT: ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; case VINUM_RESETCONFIG: if (vinum_inactive() && (vinum_conf.opencount < 2)) { /* if we're not active */ /* Note the open count. We may be called from v, so we'll be open. * Keep the count so we don't underflow */ int oc = vinum_conf.opencount; free_vinum(1); /* clean up everything */ printf("vinum: CONFIGURATION OBLITERATED\n"); vinum_conf.opencount = oc; ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; } return EBUSY; case VINUM_SETSTATE: setstate((struct vinum_ioctl_msg *) data); /* set an object state */ return 0; case VINUM_MEMINFO: vinum_meminfo(data); return 0; case VINUM_MALLOCINFO: return vinum_mallocinfo(data); + case VINUM_RQINFO: + return vinum_rqinfo(data); + case VINUM_LABEL: /* label a volume */ ioctl_reply->error = write_volume_label(*(int *) data); /* index of the volume to label */ ioctl_reply->msg[0] = '\0'; /* no message */ return 0; case VINUM_REMOVE: remove((struct vinum_ioctl_msg *) data); /* remove an object */ return 0; case VINUM_GETFREELIST: /* get a drive free list element */ index = *(int *) data; /* get the drive index */ fe = ((int *) data)[1]; /* and the free list element */ if ((index >= (unsigned) vinum_conf.drives_used) /* plex doesn't exist */ ||(DRIVE[index].state == drive_unallocated)) return ENODEV; if (fe >= DRIVE[index].freelist_entries) /* no such entry */ return ENOENT; bcopy(&DRIVE[index].freelist[fe], data, sizeof(struct drive_freelist)); return 0; case VINUM_GETDEFECTIVE: /* get a plex defective area element */ index = *(int *) data; /* get the plex index */ fe = ((int *) data)[1]; /* and the region number */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(PLEX[index].state == plex_unallocated)) return ENODEV; if (fe >= PLEX[index].defective_regions) /* no such entry */ return ENOENT; bcopy(&PLEX[index].defective_region[fe], data, sizeof(struct plexregion)); return 0; case VINUM_GETUNMAPPED: /* get a plex unmapped area element */ index = *(int *) data; /* get the plex index */ fe = ((int *) data)[1]; /* and the region number */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(PLEX[index].state == plex_unallocated)) return ENODEV; if (fe >= PLEX[index].unmapped_regions) /* no such entry */ return ENOENT; bcopy(&PLEX[index].unmapped_region[fe], data, sizeof(struct plexregion)); return 0; case VINUM_RESETSTATS: resetstats((struct vinum_ioctl_msg *) data); /* reset object stats */ return 0; /* attach an object to a superordinate object */ case VINUM_ATTACH: attachobject((struct vinum_ioctl_msg *) data); return 0; /* detach an object from a superordinate object */ case VINUM_DETACH: detachobject((struct vinum_ioctl_msg *) data); return 0; /* rename an object */ case VINUM_RENAME: renameobject((struct vinum_rename_msg *) data); return 0; /* replace an object */ case VINUM_REPLACE: replaceobject((struct vinum_ioctl_msg *) data); return 0; default: /* FALLTHROUGH */ } default: #if __FreeBSD__>=3 printf("vinumioctl: type %d, sd %d, plex %d, major %x, volume %d, command %lx\n", device->type, device->sd, device->plex, device->major, device->volume, cmd); /* XXX */ #else printf("vinumioctl: type %d, sd %d, plex %d, major %x, volume %d, command %x\n", device->type, device->sd, device->plex, device->major, device->volume, cmd); /* XXX */ #endif return EINVAL; case VINUM_DRIVE_TYPE: case VINUM_PLEX_TYPE: return EAGAIN; /* try again next week */ case VINUM_SD_TYPE: objno = SDNO(dev); switch (cmd) { case VINUM_INITSD: /* initialize subdisk */ return initsd(objno); default: return EINVAL; } break; case VINUM_VOLUME_TYPE: objno = VOLNO(dev); if ((unsigned) objno >= (unsigned) vinum_conf.volumes_used) /* not a valid volume */ return ENXIO; vol = &VOL[objno]; if (vol->state != volume_up) /* not up, */ return EIO; /* I/O error */ switch (cmd) { case DIOCGDINFO: /* get disk label */ get_volume_label(vol, (struct disklabel *) data); break; /* Care! DIOCGPART returns *pointers* to * the caller, so we need to store this crap as well. * And yes, we need it. */ case DIOCGPART: /* get partition information */ get_volume_label(vol, &vol->label); ((struct partinfo *) data)->disklab = &vol->label; ((struct partinfo *) data)->part = &vol->label.d_partitions[0]; break; /* We don't have this stuff on hardware, * so just pretend to do it so that * utilities don't get upset. */ case DIOCWDINFO: /* write partition info */ case DIOCSDINFO: /* set partition info */ return 0; /* not a titty */ case DIOCWLABEL: /* set or reset label writeable */ if ((flag & FWRITE) == 0) /* not writeable? */ return EACCES; /* no, die */ if (*(int *) data != 0) /* set it? */ vol->flags |= VF_WLABEL; /* yes */ else vol->flags &= ~VF_WLABEL; /* no, reset */ break; default: return ENOTTY; /* not my kind of ioctl */ } break; } return 0; /* XXX */ } /* The following four functions check the supplied * object index and return a pointer to the object * if it exists. Otherwise they longjump out via * throw_rude_remark */ struct drive * validdrive(int driveno, struct _ioctl_reply *reply) { if ((driveno < vinum_conf.drives_used) && (DRIVE[driveno].state != drive_unallocated)) return &DRIVE[driveno]; strcpy(reply->msg, "No such drive"); reply->error = ENOENT; return NULL; } struct sd * validsd(int sdno, struct _ioctl_reply *reply) { if ((sdno < vinum_conf.subdisks_used) && (SD[sdno].state != sd_unallocated)) return &SD[sdno]; strcpy(reply->msg, "No such subdisk"); reply->error = ENOENT; return NULL; } struct plex * validplex(int plexno, struct _ioctl_reply *reply) { if ((plexno < vinum_conf.plexes_used) && (PLEX[plexno].state != plex_unallocated)) return &PLEX[plexno]; strcpy(reply->msg, "No such plex"); reply->error = ENOENT; return NULL; } struct volume * validvol(int volno, struct _ioctl_reply *reply) { if ((volno < vinum_conf.volumes_used) && (VOL[volno].state != volume_unallocated)) return &VOL[volno]; strcpy(reply->msg, "No such volume"); reply->error = ENOENT; return NULL; } /* reset an object's stats */ void resetstats(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; switch (msg->type) { case drive_object: if (msg->index < vinum_conf.drives_used) { struct drive *drive = &DRIVE[msg->index]; if (drive->state != drive_unallocated) { drive->reads = 0; /* number of reads on this drive */ drive->writes = 0; /* number of writes on this drive */ drive->bytes_read = 0; /* number of bytes read */ drive->bytes_written = 0; /* number of bytes written */ reply->error = 0; return; } reply->error = EINVAL; return; } case sd_object: if (msg->index < vinum_conf.subdisks_used) { struct sd *sd = &SD[msg->index]; if (sd->state != sd_unallocated) { sd->reads = 0; /* number of reads on this subdisk */ sd->writes = 0; /* number of writes on this subdisk */ sd->bytes_read = 0; /* number of bytes read */ sd->bytes_written = 0; /* number of bytes written */ reply->error = 0; return; } reply->error = EINVAL; return; } break; case plex_object: if (msg->index < vinum_conf.plexes_used) { struct plex *plex = &PLEX[msg->index]; if (plex->state != plex_unallocated) { plex->reads = 0; plex->writes = 0; /* number of writes on this plex */ plex->bytes_read = 0; /* number of bytes read */ plex->bytes_written = 0; /* number of bytes written */ plex->multiblock = 0; /* requests that needed more than one block */ plex->multistripe = 0; /* requests that needed more than one stripe */ reply->error = 0; return; } reply->error = EINVAL; return; } break; case volume_object: if (msg->index < vinum_conf.volumes_used) { struct volume *vol = &VOL[msg->index]; if (vol->state != volume_unallocated) { vol->bytes_read = 0; /* number of bytes read */ vol->bytes_written = 0; /* number of bytes written */ vol->reads = 0; /* number of reads on this volume */ vol->writes = 0; /* number of writes on this volume */ vol->recovered_reads = 0; /* reads recovered from another plex */ reply->error = 0; return; } reply->error = EINVAL; return; } case invalid_object: /* can't get this */ reply->error = EINVAL; return; } } /* attach an object to a superior object */ void attachobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct sd *sd; struct plex *plex; struct volume *vol; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ case volume_object: /* nor a volume */ case invalid_object: /* "this can't happen" */ reply->error = EINVAL; reply->msg[0] = '\0'; /* vinum(8) doesn't do this */ return; case sd_object: sd = validsd(msg->index, reply); if (sd == NULL) /* not a valid subdisk */ return; plex = validplex(msg->otherobject, reply); if (plex) { if (sd->plexno >= 0) { /* already belong to a plex */ reply->error = EBUSY; /* no message, the user should check */ reply->msg[0] = '\0'; return; } sd->plexoffset = msg->offset; /* this is where we want it */ set_sd_state(sd->sdno, sd_stale, setstate_force); /* make sure it's stale */ give_sd_to_plex(plex->plexno, sd->sdno); /* and give it to the plex */ update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } break; case plex_object: plex = validplex(msg->index, reply); /* get plex */ if (plex == NULL) return; if (plex->organization != plex_concat) { /* can't attach to striped and raid-5 */ reply->error = EINVAL; /* no message, the user should check */ reply->msg[0] = '\0'; return; } vol = validvol(msg->otherobject, reply); /* and volume information */ if (vol) { if ((vol->plexes == MAXPLEX) /* we have too many already */ ||(plex->volno >= 0)) { /* or the plex has an owner */ reply->error = EINVAL; /* no message, the user should check */ reply->msg[0] = '\0'; return; } set_plex_state(plex->plexno, plex_down, setstate_force); /* make sure it's down */ give_plex_to_volume(msg->otherobject, msg->index); /* and give it to the volume */ update_plex_config(plex->plexno, 0); save_config(); if (plex->state == plex_reviving) reply->error = EAGAIN; /* need to revive it */ else reply->error = 0; } } } /* detach an object from a superior object */ void detachobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct sd *sd; struct plex *plex; struct volume *vol; int sdno; int plexno; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ case volume_object: /* nor a volume */ case invalid_object: /* "this can't happen" */ reply->error = EINVAL; reply->msg[0] = '\0'; /* vinum(8) doesn't do this */ return; case sd_object: sd = validsd(msg->index, reply); if (sd == NULL) return; if (sd->plexno < 0) { /* doesn't belong to a plex */ reply->error = ENOENT; strcpy(reply->msg, "Subdisk is not attached"); return; } else { /* valid plex number */ plex = &PLEX[sd->plexno]; if ((!msg->force) /* don't force things */ &&((plex->state == plex_up) /* and the plex is up */ ||((plex->state == plex_flaky) && sd->state == sd_up))) { /* or flaky with this sd up */ reply->error = EBUSY; /* we need this sd */ reply->msg[0] = '\0'; return; } sd->plexno = -1; /* anonymous sd */ if (plex->subdisks == 1) { /* this was the only subdisk */ Free(plex->sdnos); /* free the subdisk array */ plex->sdnos = NULL; /* and note the fact */ plex->subdisks_allocated = 0; /* no subdisk space */ } else { for (sdno = 0; sdno < plex->subdisks; sdno++) { if (plex->sdnos[sdno] == msg->index) /* found our subdisk */ break; } if (sdno < (plex->subdisks - 1)) /* not the last one, compact */ bcopy(&plex->sdnos[sdno + 1], &plex->sdnos[sdno], (plex->subdisks - 1 - sdno) * sizeof(int)); } plex->subdisks--; rebuild_plex_unmappedlist(plex); /* rebuild the unmapped list */ if (!bcmp(plex->name, sd->name, strlen(plex->name))) { /* this subdisk is named after the plex */ bcopy(sd->name, &sd->name[3], min(strlen(sd->name), MAXSDNAME - 3)); bcopy("ex-", sd->name, 3); sd->name[MAXSDNAME - 1] = '\0'; } update_plex_config(plex->plexno, 0); if ((plex->organization == plex_striped) /* we've just mutilated our plex, */ ||(plex->organization == plex_striped)) /* the data no longer matches */ set_plex_state(plex->plexno, plex_down, setstate_force | setstate_configuring); update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } return; case plex_object: plex = validplex(msg->index, reply); /* get plex */ if (plex == NULL) return; if (plex->volno >= 0) { int volno = plex->volno; vol = &VOL[volno]; if ((!msg->force) /* don't force things */ &&((vol->state == volume_up) /* and the volume is up */ &&(vol->plexes == 1))) { /* and this is the last plex */ /* XXX As elsewhere, check whether we will lose * mapping by removing this plex */ reply->error = EBUSY; /* we need this plex */ reply->msg[0] = '\0'; return; } plex->volno = -1; /* anonymous plex */ for (plexno = 0; plexno < vol->plexes; plexno++) { if (vol->plex[plexno] == msg->index) /* found our plex */ break; } if (plexno < (vol->plexes - 1)) /* not the last one, compact */ bcopy(&vol[plexno + 1], &vol[plexno], (vol->plexes - 1 - plexno) * sizeof(int)); vol->plexes--; if (!bcmp(vol->name, plex->name, strlen(vol->name))) { /* this plex is named after the volume */ /* First, check if the subdisks are the same */ if (msg->recurse) { int sdno; for (sdno = 0; sdno < plex->subdisks; sdno++) { struct sd *sd = &SD[plex->sdnos[sdno]]; if (!bcmp(plex->name, sd->name, strlen(plex->name))) { /* subdisk is named after the plex */ bcopy(sd->name, &sd->name[3], min(strlen(sd->name), MAXSDNAME - 3)); bcopy("ex-", sd->name, 3); sd->name[MAXSDNAME - 1] = '\0'; } } } bcopy(plex->name, &plex->name[3], min(strlen(plex->name), MAXPLEXNAME - 3)); bcopy("ex-", plex->name, 3); plex->name[MAXPLEXNAME - 1] = '\0'; } update_plex_config(plex->plexno, 0); update_volume_config(volno, 0); save_config(); reply->error = 0; } else { reply->error = ENOENT; strcpy(reply->msg, "Plex is not attached"); } } } void renameobject(struct vinum_rename_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct drive *drive; struct sd *sd; struct plex *plex; struct volume *vol; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ if (find_drive(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } drive = validdrive(msg->index, reply); if (drive) { bcopy(msg->newname, drive->label.name, MAXDRIVENAME); save_config(); reply->error = 0; } return; case sd_object: /* you can't attach a subdisk to anything */ if (find_subdisk(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } sd = validsd(msg->index, reply); if (sd) { bcopy(msg->newname, sd->name, MAXSDNAME); update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } return; case plex_object: /* you can't attach a plex to anything */ if (find_plex(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } plex = validplex(msg->index, reply); if (plex) { bcopy(msg->newname, plex->name, MAXPLEXNAME); update_plex_config(plex->plexno, 0); save_config(); reply->error = 0; } return; case volume_object: /* you can't attach a volume to anything */ if (find_volume(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } vol = validvol(msg->index, reply); if (vol) { bcopy(msg->newname, vol->name, MAXVOLNAME); update_volume_config(msg->index, 0); save_config(); reply->error = 0; } return; case invalid_object: reply->error = EINVAL; reply->msg[0] = '\0'; } } /* Replace one object with another */ void replaceobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; reply->error = ENODEV; /* until I know how to do this */ strcpy(reply->msg, "replace not implemented yet"); /* save_config (); */ } diff --git a/lkm/vinum/vinumkw.h b/lkm/vinum/vinumkw.h index 1a81f37656f4..597d160ad2b1 100644 --- a/lkm/vinum/vinumkw.h +++ b/lkm/vinum/vinumkw.h @@ -1,120 +1,120 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumkw.h,v 1.7 1998/08/07 02:35:51 grog Exp grog $ + * $Id: vinumkw.h,v 1.8 1998/09/29 05:17:39 grog Exp grog $ */ /* Command keywords that vinum knows. These include both user-level * and kernel-level stuff */ /* Our complete vocabulary. The names of the commands are * the same as the identifier without the kw_ at the beginning * (i.e. kw_create defines the "create" keyword). Preprocessor * magic in parser.c does the rest. */ enum keyword { kw_create, kw_modify, kw_list, kw_l = kw_list, kw_ld, /* list drive */ kw_ls, /* list subdisk */ kw_lp, /* list plex */ kw_lv, /* list volume */ kw_set, kw_rm, kw_start, kw_stop, kw_drive, kw_sd, kw_subdisk = kw_sd, kw_plex, kw_volume, kw_vol = kw_volume, kw_read, kw_readpol, kw_org, kw_name, kw_concat, kw_striped, kw_raid5, kw_driveoffset, kw_plexoffset, kw_len, kw_length = kw_len, kw_state, kw_setupstate, kw_d, /* flag names */ kw_f, kw_r, kw_s, kw_v, kw_round, /* round robin */ kw_prefer, /* prefer plex */ kw_device, kw_init, kw_label, kw_resetconfig, kw_writethrough, kw_writeback, kw_raw, kw_resetstats, kw_attach, kw_detach, kw_rename, kw_printconfig, kw_replace, kw_detached, #ifdef DEBUG kw_debug, /* go into debugger */ - kw_info, #endif + kw_info, kw_invalid_keyword = -1 }; struct _keywords { char *name; enum keyword keyword; }; struct keywordset { int size; struct _keywords *k; }; extern struct _keywords keywords[]; extern struct _keywords flag_keywords[]; extern struct keywordset keyword_set; extern struct keywordset flag_set; diff --git a/lkm/vinum/vinumvar.h b/lkm/vinum/vinumvar.h index ca54f76aad02..ee347fca0be8 100644 --- a/lkm/vinum/vinumvar.h +++ b/lkm/vinum/vinumvar.h @@ -1,510 +1,517 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: vinumvar.h,v 1.15 1998/08/14 06:36:41 grog Exp grog $ */ /* XXX gdb can't find our global pointers, so use this kludge to * point to them locally. Remove after testing */ #define BROKEN_GDB struct _vinum_conf *VC = &vinum_conf #include #include "vinumstate.h" /* Some configuration maxima. They're an enum because * we can't define global constants. Sorry about that. * * These aren't as bad as they look: most of them * are soft limits. Only the MAXCONFIG parameter is set in stone */ enum constants { VINUM_HEADER = 512, /* size of header on disk */ MAXCONFIGLINE = 1024, /* maximum size of a single config line */ /* XXX Do we still need this? */ MINVINUMSLICE = 1048576, /* minimum size of a slice */ CDEV_MAJOR = 91, /* major number for character device */ BDEV_MAJOR = 25, /* and block device */ ROUND_ROBIN_READPOL = -1, /* round robin read policy */ /* type field in minor number */ VINUM_VOLUME_TYPE = 0, VINUM_PLEX_TYPE = 1, VINUM_SD_TYPE = 2, VINUM_DRIVE_TYPE = 3, VINUM_SUPERDEV_TYPE = 4, /* super device. */ /* Shifts for the individual fields in the device */ VINUM_TYPE_SHIFT = 28, VINUM_VOL_SHIFT = 0, VINUM_PLEX_SHIFT = 16, VINUM_SD_SHIFT = 20, VINUM_VOL_WIDTH = 8, VINUM_PLEX_WIDTH = 3, VINUM_SD_WIDTH = 8, MAJORDEV_SHIFT = 8, /* Create a block device number */ #define VINUMBDEV(v,p,s,t) ((BDEV_MAJOR << MAJORDEV_SHIFT) \ | (v << VINUM_VOL_SHIFT) \ | (p << VINUM_PLEX_SHIFT) \ | (s << VINUM_SD_SHIFT) \ | (t << VINUM_TYPE_SHIFT) ) /* And a character device number */ #define VINUMCDEV(v,p,s,t) ((CDEV_MAJOR << MAJORDEV_SHIFT) \ | (v << VINUM_VOL_SHIFT) \ | (p << VINUM_PLEX_SHIFT) \ | (s << VINUM_SD_SHIFT) \ | (t << VINUM_TYPE_SHIFT) ) /* extract device type */ #define DEVTYPE(x) ((x >> VINUM_TYPE_SHIFT) & 7) /* extract volume number */ #define VOLNO(x) (x & ((1 << VINUM_VOL_WIDTH) - 1)) /* extract plex number */ #define PLEXNO(x) (VOL [VOLNO (x)].plex [(x >> VINUM_PLEX_SHIFT) & ((1 << VINUM_PLEX_WIDTH) - 1)]) /* extract subdisk number */ #define SDNO(x) (PLEX [PLEXNO (x)].sdnos [(x >> VINUM_SD_SHIFT) & ((1 << VINUM_SD_WIDTH) - 1)]) /* extract drive number */ #define DRIVENO(x) (SD [SDNO (x)].driveno) VINUM_SUPERDEV = VINUMBDEV(0, 0, 0, VINUM_SUPERDEV_TYPE), /* superdevice number */ /* the number of object entries to cater for initially, and also the * value by which they are incremented. It doesn't take long * to extend them, so theoretically we could start with 1 of each, but * it's untidy to allocate such small areas. These values are * probably too small. */ INITIAL_DRIVES = 4, INITIAL_VOLUMES = 4, INITIAL_PLEXES = 8, INITIAL_SUBDISKS = 16, INITIAL_SUBDISKS_IN_PLEX = 4, /* number of subdisks to allocate to a plex */ INITIAL_SUBDISKS_IN_DRIVE = 4, /* number of subdisks to allocate to a drive */ INITIAL_DRIVE_FREELIST = 16, /* number of entries in drive freelist */ PLEX_REGION_TABLE_SIZE = 8, /* number of entries in plex region tables */ INITIAL_LOCKS = 8, /* number of locks to allocate to a volume */ DEFAULT_REVIVE_BLOCKSIZE = 32768, /* size of block to transfer in one op */ }; /* device numbers */ /* * 31 30 28 27 20 19 18 16 15 8 7 0 * |-----------------------------------------------------------------------------------------------| * |X | Type | Subdisk number | X| Plex | Major number | volume number | * |-----------------------------------------------------------------------------------------------| * * 0x2 03 1 19 06 */ struct devcode { /* CARE. These fields assume a big-endian word. On a * little-endian system, they're the wrong way around */ unsigned volume:8; /* up to 256 volumes */ unsigned major:8; /* this is where the major number fits */ unsigned plex:3; /* up to 8 plexes per volume */ unsigned unused:1; /* up for grabs */ unsigned sd:8; /* up to 256 subdisks per plex */ unsigned type:3; /* type of object */ /* type field VINUM_VOLUME = 0, VINUM_PLEX = 1, VINUM_SUBDISK = 2, VINUM_DRIVE = 3, VINUM_SUPERDEV = 4, */ unsigned signbit:1; /* to make 32 bits */ }; #define VINUM_DIR "/dev/vinum" #define VINUM_RDIR "/dev/rvinum" #define VINUM_SUPERDEV_NAME VINUM_DIR"/control" #define MAXDRIVENAME 32 /* maximum length of a device name */ #define MAXSDNAME 64 /* maximum length of a subdisk name */ #define MAXPLEXNAME 64 /* maximum length of a plex name */ #define MAXVOLNAME 64 /* maximum length of a volume name */ #define MAXNAME 64 /* maximum length of any name */ #define MAXVOLPLEX 8 /* maximum number of plexes in a volume */ /* Flags for all objects. Most of them only apply to * specific objects, but we have space for all in any * 32 bit flags word. */ enum objflags { VF_LOCKED = 1, /* somebody has locked access to this object */ VF_LOCKING = 2, /* we want access to this object */ VF_WRITETHROUGH = 8, /* volume: write through */ VF_INITED = 0x10, /* unit has been initialized */ VF_WLABEL = 0x20, /* label area is writable */ VF_LABELLING = 0x40, /* unit is currently being labelled */ VF_WANTED = 0x80, /* someone is waiting to obtain a lock */ VF_RAW = 0x100, /* raw volume (no file system) */ VF_LOADED = 0x200, /* module is loaded */ VF_CONFIGURING = 0x400, /* somebody is changing the config */ VF_WILL_CONFIGURE = 0x800, /* somebody wants to change the config */ VF_CONFIG_INCOMPLETE = 0x1000, /* haven't finished changing the config */ VF_CONFIG_SETUPSTATE = 0x2000, /* set a volume up if all plexes are empty */ VF_READING_CONFIG = 0x4000, /* we're reading config database from disk */ VF_KERNELOP = 0x8000, /* we're performing ops from kernel space */ + VF_DIRTYCONFIG = 0x10000, /* config needs updating */ }; /* Global configuration information for the vinum subsystem */ struct _vinum_conf { /* Pointers to vinum structures */ struct drive *drive; struct sd *sd; struct plex *plex; struct volume *volume; /* the number allocated */ int drives_allocated; int subdisks_allocated; int plexes_allocated; int volumes_allocated; /* and the number currently in use */ int drives_used; int subdisks_used; int plexes_used; int volumes_used; int flags; int opencount; /* number of times we've been opened */ #if DEBUG int lastrq; struct buf *lastbuf; + struct rqinfo **rqipp; + struct rqinfo *rqinfop; #endif }; /* Use these defines to simplify code */ #define DRIVE vinum_conf.drive #define SD vinum_conf.sd #define PLEX vinum_conf.plex #define VOL vinum_conf.volume #define VFLAGS vinum_conf.flags /* Slice header * Vinum drives start with this structure: * - * Sector + *\ Sector * |--------------------------------------| * | PDP-11 memorial boot block | 0 * |--------------------------------------| * | Disk label, maybe | 1 * |--------------------------------------| * | Slice definition (vinum_hdr) | 2 * |--------------------------------------| * | | * | Configuration info, first copy | 3 * | | * |--------------------------------------| * | | * | Configuration info, second copy | 3 + size of config * | | * |--------------------------------------| */ /* Sizes and offsets of our information */ enum { VINUM_LABEL_OFFSET = 4096, /* offset of vinum label */ VINUMHEADERLEN = 512, /* size of vinum label */ VINUM_CONFIG_OFFSET = 4608, /* offset of first config copy */ MAXCONFIG = 65536, /* and size of config copy */ DATASTART = (MAXCONFIG * 2 + VINUM_CONFIG_OFFSET) / DEV_BSIZE /* this is where the data starts */ }; /* hostname is 256 bytes long, but we don't need to shlep * multiple copies in vinum. We use the host name just * to identify this system, and 32 bytes should be ample * for that purpose */ #define VINUMHOSTNAMELEN 32 struct vinum_label { char sysname[VINUMHOSTNAMELEN]; /* system name at time of creation */ char name[MAXDRIVENAME]; /* our name of the drive */ struct timeval date_of_birth; /* the time it was created */ struct timeval last_update; /* and the time of last update */ off_t drive_size; /* total size in bytes of the drive. * This value includes the headers */ }; struct vinum_hdr { long long magic; /* we're long on magic numbers */ /* XXX Get these right for big-endian */ #define VINUM_MAGIC 22322600044678729LL /* should be this */ #define VINUM_NOMAGIC 22322600044678990LL /* becomes this after obliteration */ int config_length; /* size in bytes of each copy of the * configuration info. * This must be a multiple of the sector size. */ struct vinum_label label; /* unique label */ }; /* Information returned from read_drive_label */ enum drive_label_info { DL_CANT_OPEN, /* invalid partition */ DL_NOT_OURS, /* valid partition, but no vinum label */ DL_DELETED_LABEL, /* valid partition, deleted label found */ DL_WRONG_DRIVE, /* drive name doesn't match */ DL_OURS /* valid partition and label found */ }; /*** Drive definitions ***/ /* A drive corresponds to a disk slice. We use a different term to show * the difference in usage: it doesn't have to be a slice, and could * theroretically be a complete, unpartitioned disk */ struct drive { enum drivestate state; /* current state */ int subdisks_allocated; /* number of entries in sd */ int subdisks_used; /* and the number used */ int blocksize; /* size of fs blocks */ u_int64_t sectors_available; /* number of sectors still available */ int secsperblock; int lasterror; /* last error on drive */ int driveno; /* index of drive in vinum_conf */ int opencount; /* number of up subdisks */ u_int64_t reads; /* number of reads on this drive */ u_int64_t writes; /* number of writes on this drive */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ dev_t dev; /* and device number */ char devicename[MAXDRIVENAME]; /* name of the slice it's on */ struct vnode *vp; /* vnode pointer */ struct proc *p; struct vinum_label label; /* and the label information */ struct partinfo partinfo; /* partition information */ int freelist_size; /* number of entries alloced in free list */ int freelist_entries; /* number of entries used in free list */ struct drive_freelist { /* sorted list of free space on drive */ u_int64_t offset; long sectors; } *freelist; }; /*** Subdisk definitions ***/ struct sd { enum sdstate state; /* state */ /* offsets in blocks */ int64_t driveoffset; /* offset on drive */ int64_t plexoffset; /* offset in plex */ u_int64_t sectors; /* and length in sectors */ int plexno; /* index of plex, if it belongs */ int driveno; /* index of the drive on which it is located */ int sdno; /* our index in vinum_conf */ int pid; /* pid of process which opened us */ u_int64_t reads; /* number of reads on this subdisk */ u_int64_t writes; /* number of writes on this subdisk */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ char name[MAXSDNAME]; /* name of subdisk */ }; /*** Plex definitions ***/ /* kinds of plex organization */ enum plexorg { plex_disorg, /* disorganized */ plex_concat, /* concatenated plex */ plex_striped, /* striped plex */ plex_raid5 /* RAID5 plex */ }; /* Region in plex (either defective or unmapped) */ struct plexregion { u_int64_t offset; /* start of region */ u_int64_t length; /* length */ }; struct plex { enum plexorg organization; /* Plex organization */ enum plexstate state; /* and current state */ u_int64_t length; /* total length of plex (max offset) */ int flags; int stripesize; /* size of stripe or raid band, in sectors */ int subdisks; /* number of associated subdisks */ int subdisks_allocated; /* number of subdisks allocated space for */ int *sdnos; /* list of component subdisks */ int plexno; /* index of plex in vinum_conf */ int volno; /* index of volume */ int volplexno; /* number of plex in volume */ int pid; /* pid of process which opened us */ /* Lock information */ int locks; /* number of locks used */ int alloclocks; /* number of locks allocated */ struct rangelock *lock; /* ranges of locked addresses */ /* Statistics */ u_int64_t reads; /* number of reads on this plex */ u_int64_t writes; /* number of writes on this plex */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ u_int64_t multiblock; /* requests that needed more than one block */ u_int64_t multistripe; /* requests that needed more than one stripe */ /* revive parameters */ u_int64_t revived; /* block number of current revive request */ int revive_blocksize; /* revive block size (bytes) */ int revive_interval; /* and time to wait between transfers */ struct request *waitlist; /* list of requests waiting on revive op */ /* geometry control */ int defective_regions; /* number of regions which are defective */ int defective_region_count; /* number of entries in defective_region */ struct plexregion *defective_region; /* list of offset/length pairs: defective sds */ int unmapped_regions; /* number of regions which are missing */ int unmapped_region_count; /* number of entries in unmapped_region */ struct plexregion *unmapped_region; /* list of offset/length pairs: missing sds */ char name[MAXPLEXNAME]; /* name of plex */ }; /*** Volume definitions ***/ #define MAXPLEX 8 /* maximum number of plexes */ struct volume { enum volumestate state; /* current state */ int plexes; /* number of plexes */ int preferred_plex; /* plex to read from, -1 for round-robin */ int last_plex_read; /* index of plex used for last read, * for round-robin */ dev_t devno; /* device number */ int flags; /* status and configuration flags */ int opencount; /* number of opens (all the same process) */ int openflags; /* flags supplied to last open(2) */ u_int64_t size; /* size of volume */ int disk; /* disk index */ int blocksize; /* logical block size */ int active; /* number of outstanding requests active */ int subops; /* and the number of suboperations */ pid_t pid; /* pid of locker */ /* Statistics */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ u_int64_t reads; /* number of reads on this volume */ u_int64_t writes; /* number of writes on this volume */ u_int64_t recovered_reads; /* reads recovered from another plex */ /* Unlike subdisks in the plex, space for the plex pointers is static */ int plex[MAXPLEX]; /* index of plexes */ char name[MAXVOLNAME]; /* name of volume */ struct disklabel label; /* for DIOCGPART */ }; /* Table expansion. Expand table, which contains oldcount * entries of type element, by increment entries, and change * oldcount accordingly */ #define EXPAND(table, element, oldcount, increment) \ { \ expand_table ((void **) &table, \ oldcount * sizeof (element), \ (oldcount + increment) * sizeof (element) ); \ oldcount += increment; \ } /* Information on vinum's memory usage */ struct meminfo { int mallocs; /* number of malloced blocks */ int total_malloced; /* total amount malloced */ int highwater; /* maximum number of mallocs */ struct mc *malloced; /* pointer to kernel table */ }; struct mc { int seq; int size; short line; short flags; #define ALLOC_KVA 1 /* allocated via kva calls */ int *databuf; /* really vm_object_t */ caddr_t address; char file[16]; }; /* These enums are used by the state transition * routines. They're in bit map format: * * Bit 0: Other plexes in the volume are down * Bit 1: Other plexes in the volume are up * Bit 2: The current plex is up * Maybe they should be local to * state.c */ enum volplexstate { volplex_onlyusdown = 0, /* we're the only plex, and we're down */ volplex_alldown, /* 1: another plex is down, and so are we */ volplex_otherup, /* 2: another plex is up */ volplex_otherupdown, /* other plexes are up and down */ volplex_onlyus, /* 4: we're up and alone */ volplex_onlyusup, /* only we are up, others are down */ volplex_allup, /* all plexes are up */ volplex_someup /* some plexes are up, including us */ }; /* state map for plex */ enum sdstates { sd_emptystate = 1, sd_downstate = 2, /* found an SD which is down */ sd_crashedstate = 4, /* found an SD which is crashed */ sd_obsoletestate = 8, /* found an SD which is obsolete */ sd_stalestate = 16, /* found an SD which is stale */ sd_rebornstate = 32, /* found an SD which is reborn */ sd_upstate = 64, /* found an SD which is up */ sd_initstate = 128, /* found an SD which is init */ sd_otherstate = 256 /* found an SD in some other state */ }; /* This is really just a parameter to pass to * set__state, but since it needs to be known * in the external definitions, we need to define * it here */ enum setstateflags { setstate_none = 0, /* no flags */ setstate_force = 1, /* force the state change */ setstate_configuring = 2, /* we're currently configuring, don't save */ setstate_recursing = 4, /* we're called from another setstate function */ - setstate_norecurse = 8 /* don't call other setstate functions */ + setstate_norecurse = 8, /* don't call other setstate functions */ + setstate_noupdate = 16 /* don't update config */ }; #ifdef DEBUG /* Debugging stuff */ #define DEBUG_ADDRESSES 1 #define DEBUG_NUMOUTPUT 2 +#define DEBUG_RESID 4 /* go into debugger in complete_rqe */ +#define DEBUG_LASTREQS 8 /* keep a circular buffer of last requests */ +#define DEBUG_REMOTEGDB 256 /* go into remote gdb */ #endif diff --git a/sys/dev/vinum/request.h b/sys/dev/vinum/request.h index b4beccca9b42..6575204c765f 100644 --- a/sys/dev/vinum/request.h +++ b/sys/dev/vinum/request.h @@ -1,159 +1,191 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: request.h,v 1.10 1998/08/03 07:15:26 grog Exp grog $ */ /* Information needed to set up a transfer */ /* struct buf is surprisingly big (about 300 * bytes), and it's part of the request, so this * value is really important. Most requests * don't need more than 2 subrequests per * plex. The table is automatically extended if * this value is too small. */ #define RQELTS 2 /* default of 2 requests per transfer */ enum xferinfo { XFR_NORMAL_READ = 1, XFR_NORMAL_WRITE = 2, /* write request in normal mode */ XFR_RECOVERY_READ = 4, XFR_DEGRADED_WRITE = 8, XFR_PARITYLESS_WRITE = 0x10, XFR_NO_PARITY_STRIPE = 0x20, /* parity stripe is not available */ XFR_DATA_BLOCK = 0x40, /* data block in request */ XFR_PARITY_BLOCK = 0x80, /* parity block in request */ XFR_BAD_SUBDISK = 0x100, /* this subdisk is dead */ XFR_MALLOCED = 0x200, /* this buffer is malloced */ #if DEBUG XFR_PHASE2 = 0x800, /* documentation only: 2nd phase write */ #endif XFR_REVIVECONFLICT = 0x1000, /* possible conflict with a revive operation */ /* operations that need a parity block */ XFR_PARITYOP = (XFR_NORMAL_WRITE | XFR_RECOVERY_READ | XFR_DEGRADED_WRITE), /* operations that use the group parameters */ XFR_GROUPOP = (XFR_DEGRADED_WRITE | XFR_RECOVERY_READ), /* operations that that use the data parameters */ XFR_DATAOP = (XFR_NORMAL_READ | XFR_NORMAL_WRITE | XFR_PARITYLESS_WRITE), /* operations requiring read before write */ XFR_RBW = (XFR_NORMAL_WRITE | XFR_DEGRADED_WRITE), /* operations that need a malloced buffer */ XFR_NEEDS_MALLOC = (XFR_NORMAL_WRITE | XFR_RECOVERY_READ | XFR_DEGRADED_WRITE) }; /* Describe one low-level request, part * of a high-level request. This is an * extended struct buf buffer, and the first * element *must* be a struct buf. We pass this structure * to the I/O routines instead of a struct buf in oder * to be able to locate the high-level request when it * completes. * * All offsets and lengths are in "blocks", i.e. sectors */ struct rqelement { struct buf b; /* buf structure */ struct rqgroup *rqg; /* pointer to our group */ /* Information about the transfer */ daddr_t sdoffset; /* offset in subdisk */ int useroffset; /* offset in user buffer of normal data */ /* dataoffset and datalen refer to "individual" * data transfers (normal read, parityless write) * and also degraded write. * * groupoffset and grouplen refer to the other * "group" operations (normal write, recovery read) * Both the offsets are relative to the start of the * local buffer */ int dataoffset; /* offset in buffer of the normal data */ int groupoffset; /* offset in buffer of group data */ short datalen; /* length of normal data (sectors) */ short grouplen; /* length of group data (sectors) */ short buflen; /* total buffer length to allocate */ short flags; /* really enum xferinfo (see above) */ /* Ways to find other components */ short sdno; /* subdisk number */ short driveno; /* drive number */ }; /* A group of requests built to satisfy a certain * component of a user request */ struct rqgroup { struct rqgroup *next; /* pointer to next group */ struct request *rq; /* pointer to the request */ short count; /* number of requests in this group */ short active; /* and number active */ short plexno; /* index of plex */ int badsdno; /* index of bad subdisk or -1 */ enum xferinfo flags; /* description of transfer */ struct rqelement rqe[0]; /* and the elements of this request */ }; /* Describe one high-level request and the * work we have to do to satisfy it */ struct request { struct buf *bp; /* pointer to the high-level request */ int flags; union { int volno; /* volume index */ int plexno; /* or plex index */ } volplex; int error; /* current error indication */ short isplex; /* set if this is a plex request */ short active; /* number of subrequests still active */ struct rqgroup *rqg; /* pointer to the first group of requests */ struct rqgroup *lrqg; /* and to the first group of requests */ struct request *next; /* link of waiting requests */ }; /* Extended buffer header for subdisk I/O. Includes * a pointer to the user I/O request. */ struct sdbuf { struct buf b; /* our buffer */ struct buf *bp; /* and pointer to parent */ short driveno; /* drive index */ short sdno; /* and subdisk index */ }; /* Values returned by rqe and friends. * Be careful with these: they are in order of increasing * seriousness. Some routines check for > REQUEST_RECOVERED * to indicate a completely failed request. */ enum requeststatus { REQUEST_OK, /* request built OK */ REQUEST_RECOVERED, /* request OK, but involves RAID5 recovery */ REQUEST_EOF, /* request failed: outside plex */ REQUEST_DOWN, /* request failed: subdisk down */ REQUEST_ENOMEM /* ran out of memory */ }; + +#ifdef DEBUG +/* Trace entry for request info (DEBUG_LASTREQS) */ +enum rqinfo_type { + loginfo_unused, /* never been used */ + loginfo_user_bp, /* this is the bp when strategy is called */ + loginfo_user_bpl, /* and this is the bp at launch time */ + loginfo_rqe, /* user RQE */ + loginfo_iodone, /* iodone */ + loginfo_raid5_data, /* write RAID-5 data block */ + loginfo_raid5_parity /* write RAID-5 parity block */ +}; + +union rqinfou { /* info to pass to logrq */ + struct buf *bp; + struct rqelement *rqe; /* address of request, for correlation */ +}; + +struct rqinfo { + enum rqinfo_type type; /* kind of event */ + struct timeval timestamp; /* time it happened */ + struct buf *bp; /* point to user buffer */ + union { + struct buf b; /* yup, the *whole* buffer header */ + struct rqelement rqe; /* and the whole rqe */ + } info; +}; + +#define RQINFO_SIZE 64 /* number of info slots in buffer */ + +void logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp); +#endif diff --git a/sys/dev/vinum/vinumconfig.c b/sys/dev/vinum/vinumconfig.c index fd31c5e07c46..4875eb6a7378 100644 --- a/sys/dev/vinum/vinumconfig.c +++ b/sys/dev/vinum/vinumconfig.c @@ -1,1712 +1,1713 @@ /* To do: * Don't store drive configuration on the config DB: read each drive's header * to decide where it is. * * Accept any old crap in the config_ functions, and complain when * we try to bring it up. * * When trying to bring volumes up, check that the complete address range * is covered. */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: config.c,v 1.17 1998/08/14 04:49:26 grog Exp grog $ + * $Id: config.c,v 1.19 1998/10/05 02:48:15 grog Exp grog $ */ #define STATIC /* nothing while we're testing XXX */ #define REALLYKERNEL #include "vinumhdr.h" extern jmp_buf command_fail; /* return on a failed command */ #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ void longjmp(jmp_buf, int); #endif #define MAXTOKEN 64 /* maximum number of tokens in a line */ /* We can afford the luxury of global variables here, * since start_config ensures that these functions * are single-threaded. */ /* These are indices in vinum_conf of the last-mentioned of each kind of object */ static int current_drive = -1; /* note the last drive we mention, for * some defaults */ static int current_plex = -1; /* and the same for the last plex */ static int current_volume = -1; /* and the last volme */ static struct _ioctl_reply *ioctl_reply; /* struct to return via ioctl */ /* These values are used by most of these routines, so set them as globals */ static char *token[MAXTOKEN]; /* pointers to individual tokens */ static int tokens; /* number of tokens */ #define TOCONS 0x01 #define TOTTY 0x02 #define TOLOG 0x04 struct putchar_arg { int flags; struct tty *tty; }; #define MSG_MAX 1024 /* maximum length of a formatted message */ /* Format an error message and return to the user in the reply. * CARE: This routine is designed to be called only from the * configuration routines, so it assumes it's the owner of * the configuration lock, and unlocks it on exit */ void throw_rude_remark(int error, char *msg,...) { BROKEN_GDB; int retval; va_list ap; char *text; static int finishing; /* don't recurse */ int was_finishing; va_start(ap, msg); if ((ioctl_reply != NULL) /* we're called from the user */ &&(!(vinum_conf.flags & VF_KERNELOP))) { /* and we're not doing kernel things: return msg */ /* XXX We can't just format to ioctl_reply, since it * may contain our input parameters */ text = Malloc(MSG_MAX); if (text == NULL) { printf("vinum: can't allocate error message buffer"); printf("vinum: "); vprintf(msg, ap); /* print to the console */ printf("\n"); } else { retval = kvprintf(msg, NULL, (void *) text, 10, ap); text[retval] = '\0'; /* delimit */ strcpy(ioctl_reply->msg, text); ioctl_reply->error = error; /* first byte is the error number */ Free(text); } } else { printf("vinum: "); vprintf(msg, ap); /* print to the console */ printf("\n"); } va_end(ap); if (vinum_conf.flags & VF_READING_CONFIG) /* go through to the bitter end, */ return; /* We have a problem here: we want to unlock the * configuration, which implies tidying up, but * if we find an error while tidying up, we could * recurse for ever. Use this kludge to only try * once */ was_finishing = finishing; finishing = 1; finish_config(was_finishing); /* unlock anything we may be holding */ finishing = was_finishing; longjmp(command_fail, error); } /* Function declarations */ int atoi(char *); /* no atoi in the kernel */ /* Minimal version of atoi */ int atoi(char *s) { /* no atoi in the kernel */ BROKEN_GDB; int r = 0; int sign = 1; while (((*s >= '0') && (*s <= '9')) || (*s == '-')) { if (*s == '-') sign = -sign; else r = r * 10 + (*s - '0'); } return r; } /* Find index of volume in vinum_conf. Return the index * if found, or -1 if not */ int volume_index(struct volume *vol) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.volumes_used; i++) if (&VOL[i] == vol) return i; return -1; } /* Find index of plex in vinum_conf. Return the index * if found, or -1 if not */ int plex_index(struct plex *plex) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.plexes_used; i++) if (&PLEX[i] == plex) return i; return -1; } /* Find index of subdisk in vinum_conf. Return the index * if found, or -1 if not */ int sd_index(struct sd *sd) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.subdisks_used; i++) if (&SD[i] == sd) return i; return -1; } /* Find index of drive in vinum_conf. Return the index * if found, or -1 if not */ int drive_index(struct drive *drive) { BROKEN_GDB; int i; for (i = 0; i < vinum_conf.drives_used; i++) if (&DRIVE[i] == drive) return i; return -1; } /* Check a volume to see if the plex is already assigned to it. * Return index in volume->plex, or -1 if not assigned */ int my_plex(int volno, int plexno) { BROKEN_GDB; int i; struct volume *vol; vol = &VOL[volno]; /* point to volno */ for (i = 0; i < vol->plexes; i++) if (vol->plex[i] == plexno) return i; return -1; /* not found */ } /* Check a plex to see if the subdisk is already assigned to it. * Return index in plex->sd, or -1 if not assigned */ int my_sd(int plexno, int sdno) { BROKEN_GDB; int i; struct plex *plex; plex = &PLEX[plexno]; for (i = 0; i < plex->subdisks; i++) if (plex->sdnos[i] == sdno) return i; return -1; /* not found */ } /* Check that this operation is being done in the kernel. * longjmp out if not. op the name of the operation. */ void checkkernel(char *op) { BROKEN_GDB; if (vinum_conf.flags & VF_KERNELOP == 0) throw_rude_remark(EPERM, "Can't perform '%s' from user space", op); } /* Add plex to the volume if possible */ int give_plex_to_volume(int volno, int plexno) { BROKEN_GDB; struct volume *vol; /* XXX It's not an error for the plex to already * belong to the volume, but we need to check a * number of things to make sure it's done right. * Some day. */ if (my_plex(volno, plexno) >= 0) return plexno; /* that's it */ vol = &VOL[volno]; /* point to volume */ if (vol->plexes == MAXPLEX) /* all plexes allocated */ throw_rude_remark(ENOSPC, "Too many plexes for volume %s", vol->name); vol->plex[vol->plexes] = plexno; /* this one */ vol->plexes++; /* add another plex */ PLEX[plexno].volno = volno; /* note the number of our volume */ return vol->plexes - 1; /* and return its index */ } /* Add subdisk to a plex if possible */ int give_sd_to_plex(int plexno, int sdno) { BROKEN_GDB; int i; struct plex *plex; struct sd *sd; /* XXX It's not an error for the sd to already * belong to the plex, but we need to check a * number of things to make sure it's done right. * Some day. */ i = my_sd(plexno, sdno); if (i >= 0) /* does it already belong to us? */ return i; /* that's it */ plex = &PLEX[plexno]; /* point to the plex */ sd = &SD[sdno]; /* and the subdisk */ /* Do we have an offset? Otherwise put it after the last one */ if (sd->plexoffset < 0) { /* no offset specified */ if (plex->subdisks > 0) { struct sd *lastsd = &SD[plex->sdnos[plex->subdisks - 1]]; /* last subdisk */ sd->plexoffset = lastsd->sectors + lastsd->plexoffset; /* take it */ } else /* first subdisk */ sd->plexoffset = 0; /* start at the beginning */ } plex->subdisks++; /* another entry */ if (plex->subdisks >= plex->subdisks_allocated) /* need more space */ EXPAND(plex->sdnos, int, plex->subdisks_allocated, INITIAL_SUBDISKS_IN_PLEX); /* XXX I'm not sure this makes any sense * for anything except concatenated plexes, * and it comes up with the wrong answer for * RAID-5 plexes, but it's currently needed * for the calculations. We'll adjust for * RAID-5 in config_plex */ if ((sd->sectors + sd->plexoffset) > plex->length) { /* gone beyond the end of the plex */ plex->length = sd->sectors + sd->plexoffset; /* adjust the length */ if ((plex->volno >= 0) /* we have a volume */ &&(plex->length > VOL[plex->volno].size)) /* and we're now the longest plex */ VOL[plex->volno].size = plex->length; /* increase the size of the volume */ } /* We need to check that the subdisks don't overlap, * but we can't do that until a point where we *must* * know the size of all the subdisks. That's not * here. But we need to sort them by offset */ for (i = 0; i < plex->subdisks - 1; i++) { if (sd->plexoffset < SD[plex->sdnos[i]].plexoffset) { /* it fits before this one */ /* First move any remaining subdisks by one */ int j; for (j = plex->subdisks - 1; j > i; j--) /* move up one at a time */ plex->sdnos[j] = plex->sdnos[j - 1]; plex->sdnos[i] = sdno; return i; } } /* The plex doesn't have any subdisk with a larger * offset. Insert it */ plex->sdnos[i] = sdno; return i; } /* Add a subdisk to drive if possible. The pointer to the drive * must already be stored in the sd structure, but the drive * doesn't know about the subdisk yet. */ static void give_sd_to_drive(int sdno) { BROKEN_GDB; struct sd *sd; /* pointer to subdisk */ struct drive *drive; /* and drive */ int fe; /* index in free list */ sd = &SD[sdno]; /* point to sd */ drive = &DRIVE[sd->driveno]; /* and drive */ if (drive->state != drive_up) /* not up */ throw_rude_remark(EIO, "Drive %s is not accessible", drive->label.name); else if (sd->sectors > drive->sectors_available) { /* too big, */ sd->driveoffset = -1; /* don't be confusing */ throw_rude_remark(ENOSPC, "No space for %s on %s", sd->name, drive->label.name); } drive->subdisks_used++; /* one more subdisk */ /* no offset specified, find one */ if (sd->driveoffset < 0) { for (fe = 0; fe < drive->freelist_entries; fe++) { if (drive->freelist[fe].sectors >= sd->sectors) { /* it'll fit here */ sd->driveoffset = drive->freelist[fe].offset; if (sd->sectors == drive->freelist[fe].sectors) { /* used up the entire entry */ if (fe < (drive->freelist_entries - 1)) /* not the last one, */ bcopy(&drive->freelist[fe + 1], &drive->freelist[fe], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry */ } else { drive->freelist[fe].sectors -= sd->sectors; /* this much less space */ drive->freelist[fe].offset += sd->sectors; /* this much further on */ } drive->sectors_available -= sd->sectors; /* and note how much less space we have */ break; } } if (fe == drive->freelist_entries) /* Didn't find anything. Although the drive has * enough space, it's too fragmented */ { sd->driveoffset = -1; /* don't be confusing */ throw_rude_remark(ENOSPC, "No space for %s on %s", sd->name, drive->label.name); } } else { /* specific offset */ /* For a specific offset to work, the space must be * entirely in a single freelist entry. Look for it. */ u_int64_t sdend = sd->driveoffset + sd->sectors; /* end of our subdisk */ for (fe = 0; fe < drive->freelist_entries; fe++) { u_int64_t dend = drive->freelist[fe].offset + drive->freelist[fe].sectors; /* end of entry */ if (dend >= sdend) { /* fits before here */ if (drive->freelist[fe].offset > sd->driveoffset) /* starts after the beginning of sd area */ throw_rude_remark(ENOSPC, "No space for subdisk %s on drive %s at offset %qd\n", sd->name, drive->label.name); /* We've found the space, and we can allocate it. * We don't need to say that to the subdisk, which * already knows about it. We need to tell it to * the free list, though. We have four possibilities: * * 1. The subdisk exactly eats up the entry. That's the * same as above. * 2. The subdisk starts at the beginning and leaves space * at the end. * 3. The subdisk starts after the beginning and leaves * space at the end as well: we end up with another * fragment. * 4. The subdisk leaves space at the beginning and finishes * at the end. */ drive->sectors_available -= sd->sectors; /* note how much less space we have */ if (sd->driveoffset == drive->freelist[fe].offset) { /* 1 or 2 */ if (sd->sectors == drive->freelist[fe].sectors) { /* 1: used up the entire entry */ if (fe < (drive->freelist_entries - 1)) /* not the last one, */ bcopy(&drive->freelist[fe + 1], &drive->freelist[fe], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry */ } else { /* 2: space at the end */ drive->freelist[fe].sectors -= sd->sectors; /* this much less space */ drive->freelist[fe].offset += sd->sectors; /* this much further on */ } } else { /* 3 or 4 */ drive->freelist[fe].sectors = sd->driveoffset - drive->freelist[fe].offset; if (dend > sdend) { /* 3: space at the end as well */ if (fe < (drive->freelist_entries - 1)) /* not the last one */ bcopy(&drive->freelist[fe], /* move the rest down */ &drive->freelist[fe + 1], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries++; /* one less entry */ drive->freelist[fe + 1].offset = sdend; /* second entry starts after sd */ drive->freelist[fe + 1].sectors = dend - sdend; /* and is this long */ } } break; } } } drive->opencount++; /* one more subdisk attached */ } /* Get an empty drive entry from the drive table */ int get_empty_drive(void) { BROKEN_GDB; int driveno; struct drive *drive; /* first see if we have one which has been deallocated */ for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { if (DRIVE[driveno].state == drive_unallocated) /* bingo */ break; } if (driveno >= vinum_conf.drives_used) /* Couldn't find a deallocated drive. Allocate a new one */ { vinum_conf.drives_used++; if (vinum_conf.drives_used > vinum_conf.drives_allocated) /* we've used all our allocation */ EXPAND(DRIVE, struct drive, vinum_conf.drives_allocated, INITIAL_DRIVES); } /* got a drive entry. Make it pretty */ drive = &DRIVE[driveno]; bzero(drive, sizeof(struct drive)); drive->driveno = driveno; /* put number in structure */ return driveno; /* return the index */ } /* Find the named drive in vinum_conf.drive, return a pointer * return the index in vinum_conf.drive. - * Don't mark the drive as allocated (XXX MP) + * Don't mark the drive as allocated (XXX SMP) * If create != 0, create an entry if it doesn't exist */ /* XXX check if we have it open from attach */ int find_drive(const char *name, int create) { BROKEN_GDB; int driveno; struct drive *drive; if (name != NULL) { for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { drive = &DRIVE[driveno]; /* point to drive */ if ((drive->label.name[0] != '\0') /* it has a name */ &&(strcmp(drive->label.name, name) == 0)) /* and it's this one: found */ return driveno; } } /* the drive isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ driveno = get_empty_drive(); drive = &DRIVE[driveno]; if (name != NULL) bcopy(name, /* put in its name */ drive->label.name, min(sizeof(drive->label.name), strlen(name))); drive->state = drive_uninit; /* in use, nothing worthwhile there */ return driveno; /* return the index */ } /* Find a drive given its device name. * devname must be valid. * Otherwise the same as find_drive above */ int find_drive_by_dev(const char *devname, int create) { BROKEN_GDB; int driveno; struct drive *drive; for (driveno = 0; driveno < vinum_conf.drives_used; driveno++) { drive = &DRIVE[driveno]; /* point to drive */ if ((drive->label.name[0] != '\0') /* it has a name */ &&(strcmp(drive->label.name, devname) == 0)) /* and it's this one: found */ return driveno; } /* the drive isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ driveno = get_empty_drive(); drive = &DRIVE[driveno]; bcopy(devname, /* put in its name */ drive->devicename, min(sizeof(drive->devicename), strlen(devname))); drive->state = drive_uninit; /* in use, nothing worthwhile there */ return driveno; /* return the index */ } /* Find an empty subdisk in the subdisk table */ int get_empty_sd(void) { BROKEN_GDB; int sdno; struct sd *sd; /* first see if we have one which has been deallocated */ for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { if (SD[sdno].state == sd_unallocated) /* bingo */ break; } if (sdno >= vinum_conf.subdisks_used) { /* No unused sd found. Allocate a new one */ vinum_conf.subdisks_used++; if (vinum_conf.subdisks_used > vinum_conf.subdisks_allocated) EXPAND(SD, struct sd, vinum_conf.subdisks_allocated, INITIAL_SUBDISKS); } /* initialize some things */ sd = &SD[sdno]; /* point to it */ bzero(sd, sizeof(struct sd)); /* initialize */ sd->plexno = -1; /* no plex */ sd->driveno = -1; /* and no drive */ sd->plexoffset = -1; /* and no offsets */ sd->driveoffset = -1; return sdno; /* return the index */ } /* return a drive to the free pool */ void free_drive(struct drive *drive) { BROKEN_GDB; if (drive->vp != NULL) /* device open */ vn_close(drive->vp, FREAD | FWRITE, FSCRED, drive->p); bzero(drive, sizeof(struct drive)); /* this also sets drive_unallocated */ } /* Find the named subdisk in vinum_conf.sd. * If create != 0, create an entry if it doesn't exist * * Return index in vinum_conf.sd */ int find_subdisk(const char *name, int create) { BROKEN_GDB; int sdno; struct sd *sd; for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { if (strcmp(SD[sdno].name, name) == 0) /* found it */ return sdno; } /* the subdisk isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ sdno = get_empty_sd(); sd = &SD[sdno]; bcopy(name, sd->name, min(sizeof(sd->name), strlen(name))); /* put in its name */ return sdno; /* return the pointer */ } /* Free an allocated sd entry * This performs memory management only. remove() * is responsible for checking relationships. */ void free_sd(int sdno) { BROKEN_GDB; struct sd *sd; struct drive *drive; int fe; /* free list entry */ u_int64_t sdend; /* end of our subdisk */ u_int64_t dend; /* end of our freelist entry */ sd = &SD[sdno]; if ((sd->driveno >= 0) /* we have a drive, */ &&(sd->sectors > 0)) { /* and some space on it */ drive = &DRIVE[sd->driveno]; sdend = sd->driveoffset + sd->sectors; /* end of our subdisk */ /* Look for where to return the sd address space */ for (fe = 0; (fe < drive->freelist_entries) && (drive->freelist[fe].offset < sd->driveoffset); fe++); /* Now we are pointing to the last entry, the first * with a higher offset than the subdisk, or both. */ if ((fe > 1) /* not the first entry */ &&((fe == drive->freelist_entries) /* gone past the end */ ||(drive->freelist[fe].offset > sd->driveoffset))) /* or past the block were looking for */ fe--; /* point to the block before */ dend = drive->freelist[fe].offset + drive->freelist[fe].sectors; /* end of the entry */ /* At this point, we are pointing to the correct * place in the free list. A number of possibilities * exist: * * 1. The block to be freed immediately follows * the block to which we are pointing. Just * enlarge it. * 2. The block to be freed starts at the end of * the current block and ends at the beginning * of the following block. Merge the three * areas into a single block. * 3. The block to be freed starts after the end * of the block and ends before the start of * the following block. Create a new free block. * 4. The block to be freed starts after the end * of the block, but ends at the start of the * following block. Enlarge the following block * downwards. * */ if (sd->driveoffset == dend) { /* it starts after the end of this block */ if ((fe < drive->freelist_entries - 1) /* we're not the last block in the free list */ &&(sdend == drive->freelist[fe + 1].offset)) { /* and the subdisk ends at the start of the * next block */ drive->freelist[fe].sectors = drive->freelist[fe + 1].sectors; /* 2: merge all three blocks */ if (fe < drive->freelist_entries - 2) /* still more blocks after next */ bcopy(&drive->freelist[fe + 2], /* move down one */ &drive->freelist[fe + 1], (drive->freelist_entries - 2 - fe) * sizeof(struct drive_freelist)); drive->freelist_entries--; /* one less entry in the free list */ } else /* 1: just enlarge this block */ drive->freelist[fe].sectors += sd->sectors; } else { if (sd->driveoffset > dend) /* it starts after this block */ fe++; /* so look at the next block */ if ((fe < drive->freelist_entries) /* we're not the last block in the free list */ &&(sdend == drive->freelist[fe].offset)) { /* and the subdisk ends at the start of * this block: case 4 */ drive->freelist[fe].offset = sd->driveoffset; /* it starts where the sd was */ drive->freelist[fe].sectors += sd->sectors; /* and it's this much bigger */ } else { /* case 3: non-contiguous */ if (fe < drive->freelist_entries) /* not after the last block, */ bcopy(&drive->freelist[fe], /* move the rest up one entry */ &drive->freelist[fe + 1], (drive->freelist_entries - fe) * sizeof(struct drive_freelist)); drive->freelist_entries++; /* one less entry */ drive->freelist[fe].offset = sd->driveoffset; /* this entry represents the sd */ drive->freelist[fe].sectors = sd->sectors; } } drive->opencount--; /* one less subdisk attached */ } bzero(sd, sizeof(struct sd)); /* and clear it out */ sd->state = sd_unallocated; } /* Find an empty plex in the plex table */ int get_empty_plex(void) { BROKEN_GDB; int plexno; struct plex *plex; /* if we allocate one */ /* first see if we have one which has been deallocated */ for (plexno = 0; plexno < vinum_conf.plexes_used; plexno++) { if (PLEX[plexno].state == plex_unallocated) /* bingo */ break; /* and get out of here */ } if (plexno >= vinum_conf.plexes_used) { /* Couldn't find a deallocated plex. Allocate a new one */ vinum_conf.plexes_used++; if (vinum_conf.plexes_used > vinum_conf.plexes_allocated) EXPAND(PLEX, struct plex, vinum_conf.plexes_allocated, INITIAL_PLEXES); } /* Found a plex. Give it an sd structure */ plex = &PLEX[plexno]; /* this one is ours */ bzero(plex, sizeof(struct plex)); /* polish it up */ plex->sdnos = (int *) Malloc(sizeof(int) * INITIAL_SUBDISKS_IN_PLEX); /* allocate sd table */ CHECKALLOC(plex->sdnos, "vinum: Can't allocate plex subdisk table"); bzero(plex->sdnos, (sizeof(int) * INITIAL_SUBDISKS_IN_PLEX)); /* do we need this? */ plex->subdisks = 0; /* no subdisks in use */ plex->subdisks_allocated = INITIAL_SUBDISKS_IN_PLEX; /* and we have space for this many */ plex->organization = plex_disorg; /* and it's not organized */ plex->volno = -1; /* no volume yet */ return plexno; /* return the index */ } /* Find the named plex in vinum_conf.plex * If create != 0, create an entry if it doesn't exist * return index in vinum_conf.plex */ int find_plex(const char *name, int create) { BROKEN_GDB; int plexno; struct plex *plex; for (plexno = 0; plexno < vinum_conf.plexes_allocated; plexno++) { if (strcmp(PLEX[plexno].name, name) == 0) /* found it */ return plexno; } /* the plex isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ plexno = get_empty_plex(); plex = &PLEX[plexno]; /* point to it */ bcopy(name, plex->name, min(sizeof(plex->name), strlen(name))); /* put in its name */ return plexno; /* return the pointer */ } /* Free an allocated plex entry * and its associated memory areas */ void free_plex(int plexno) { BROKEN_GDB; struct plex *plex; plex = &PLEX[plexno]; if (plex->sdnos) Free(plex->sdnos); if (plex->lock) Free(plex->lock); if (plex->defective_region) Free(plex->defective_region); if (plex->unmapped_region) Free(plex->unmapped_region); bzero(plex, sizeof(struct plex)); /* and clear it out */ plex->state = plex_unallocated; } /* Find an empty volume in the volume table */ int get_empty_volume(void) { BROKEN_GDB; int volno; struct volume *vol; /* first see if we have one which has been deallocated */ for (volno = 0; volno < vinum_conf.volumes_used; volno++) { if (VOL[volno].state == volume_unallocated) /* bingo */ break; } if (volno >= vinum_conf.volumes_used) /* Couldn't find a deallocated volume. Allocate a new one */ { vinum_conf.volumes_used++; if (vinum_conf.volumes_used > vinum_conf.volumes_allocated) EXPAND(VOL, struct volume, vinum_conf.volumes_allocated, INITIAL_VOLUMES); } /* Now initialize fields */ vol = &VOL[volno]; bzero(vol, sizeof(struct volume)); vol->preferred_plex = -1; /* default to round robin */ vol->preferred_plex = ROUND_ROBIN_READPOL; /* round robin */ return volno; /* return the index */ } /* Find the named volume in vinum_conf.volume. * If create != 0, create an entry if it doesn't exist * return the index in vinum_conf */ int find_volume(const char *name, int create) { BROKEN_GDB; int volno; struct volume *vol; for (volno = 0; volno < vinum_conf.volumes_used; volno++) { if (strcmp(VOL[volno].name, name) == 0) /* found it */ return volno; } /* the volume isn't in the list. Add it if he wants */ if (create == 0) /* don't want to create */ return -1; /* give up */ /* Allocate one and insert the name */ volno = get_empty_volume(); vol = &VOL[volno]; bcopy(name, vol->name, min(sizeof(vol->name), strlen(name))); /* put in its name */ vol->blocksize = DEV_BSIZE; /* block size of this volume */ return volno; /* return the pointer */ } /* Free an allocated volume entry * and its associated memory areas */ void free_volume(int volno) { BROKEN_GDB; struct volume *vol; vol = &VOL[volno]; bzero(vol, sizeof(struct volume)); /* and clear it out */ vol->state = volume_unallocated; } /* Handle a drive definition. We store the information in the global variable * drive, so we don't need to allocate. * * If we find an error, print a message and return */ void config_drive(void) { BROKEN_GDB; enum drive_label_info partition_status; /* info about the partition */ int parameter; int driveno; /* index of drive in vinum_conf */ struct drive *drive; /* and pointer to it */ if (tokens < 2) /* not enough tokens */ throw_rude_remark(EINVAL, "Drive has no name"); driveno = find_drive(token[1], 1); /* allocate a drive to initialize */ drive = &DRIVE[driveno]; /* and get a pointer */ if (drive->state != drive_uninit) { /* we already know this drive */ /* XXX Check which definition is more up-to-date. Give * preference for the definition on its own drive */ return; /* XXX */ } for (parameter = 2; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_device: parameter++; if (drive->devicename[0] != '\0') { /* we know this drive... */ if (strcmp(drive->devicename, token[parameter])) /* different name */ close_drive(drive); /* close it if it's open */ else /* no change */ break; } bcopy(token[parameter], /* insert device information */ drive->devicename, min(sizeof(drive->devicename), strlen(token[parameter]))); /* open the device and get the configuration */ partition_status = read_drive_label(drive); if (partition_status == DL_CANT_OPEN) { /* not our kind */ close_drive(drive); if (drive->lasterror == EFTYPE) /* wrong kind of partition */ throw_rude_remark(drive->lasterror, "Drive %s has invalid partition type", drive->label.name); else /* I/O error of some kind */ throw_rude_remark(drive->lasterror, "Can't initialize drive %s", drive->label.name); } else if (partition_status == DL_WRONG_DRIVE) { /* valid drive, not ours */ close_drive(drive); throw_rude_remark(drive->lasterror, "Incorrect drive name %s specified for drive %s", token[1], drive->label.name); } break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ drive->state = DriveState(token[parameter]); /* set the state */ break; default: close_drive(drive); throw_rude_remark(EINVAL, "Drive %s, invalid keyword: %s", token[1], token[parameter]); } } - if (drive->devicename[0] == '\0') + if (drive->devicename[0] == '\0') { + drive->state = drive_unallocated; /* deallocate the drive */ throw_rude_remark(EINVAL, "No device name for %s", drive->label.name); - + } } /* Handle a subdisk definition. We store the information in the global variable * sd, so we don't need to allocate. * * If we find an error, print a message and return */ void config_subdisk(void) { BROKEN_GDB; int parameter; int sdno; /* index of sd in vinum_conf */ struct sd *sd; /* and pointer to it */ u_int64_t size; int sectors; /* sector offset value */ int detached = 0; /* set to 1 if this is a detached subdisk */ int sdindex = -1; /* index in plexes subdisk table */ sdno = get_empty_sd(); /* allocate an SD to initialize */ sd = &SD[sdno]; /* and get a pointer */ for (parameter = 1; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_detached: detached = 1; break; case kw_plexoffset: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, bad plex offset alignment: %qd", sd->name, size); else sd->plexoffset = size / DEV_BSIZE; break; case kw_driveoffset: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, bad drive offset alignment: %qd", sd->name, size); else sd->driveoffset = size / DEV_BSIZE; break; case kw_name: ++parameter; bcopy(token[parameter], sd->name, min(sizeof(sd->name), strlen(token[parameter]))); break; case kw_len: size = sizespec(token[++parameter]); if ((size % DEV_BSIZE) != 0) throw_rude_remark(EINVAL, "sd %s, length %d not multiple of sector size", sd->name, size); else sd->sectors = size / DEV_BSIZE; break; case kw_drive: sd->driveno = find_drive(token[++parameter], 1); /* insert drive information */ break; case kw_plex: sd->plexno = find_plex(token[++parameter], 1); /* insert plex information */ break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ sd->state = SdState(token[parameter]); /* set the state */ break; default: throw_rude_remark(EINVAL, "sd %s, invalid keyword: %s", sd->name, token[parameter]); } } /* Check we have a drive name */ if (sd->driveno < 0) { /* didn't specify a drive */ sd->driveno = current_drive; /* set to the current drive */ if (sd->driveno < 0) /* no current drive? */ throw_rude_remark(EINVAL, "Subdisk %s is not associated with a drive", sd->name); } /* Check for a plex name */ if ((sd->plexno < 0) /* didn't specify a plex */ &&(!detached)) /* and didn't say not to, */ sd->plexno = current_plex; /* set to the current plex */ if (sd->plexno >= 0) sdindex = give_sd_to_plex(sd->plexno, sdno); /* now tell the plex that it has this sd */ sd->sdno = sdno; /* point to our entry in the table */ /* Does the subdisk have a name? If not, give it one */ if (sd->name[0] == '\0') { /* no name */ char sdsuffix[8]; /* form sd name suffix here */ /* Do we have a plex name? */ if (sdindex >= 0) /* we have a plex */ strcpy(sd->name, PLEX[sd->plexno].name); /* take it from there */ else /* no way */ throw_rude_remark(EINVAL, "Unnamed sd is not associated with a plex"); sprintf(sdsuffix, ".s%d", sdindex); /* form the suffix */ strcat(sd->name, sdsuffix); /* and add it to the name */ } /* do we have complete info for this subdisk? */ if (sd->sectors == 0) throw_rude_remark(EINVAL, "sd %s has no length spec", sd->name); if (sd->state == sd_unallocated) /* no state decided, */ sd->state = sd_init; /* at least we're in the game */ /* register the subdisk with the drive. This action * will have the side effect of setting the offset if * we haven't specified one, and causing an error * message if it overlaps with another subdisk. */ give_sd_to_drive(sdno); } /* Handle a plex definition. * If we find an error, print a message, deallocate the nascent plex, and return */ void config_plex(void) { BROKEN_GDB; int parameter; int plexno; /* index of plex in vinum_conf */ struct plex *plex; /* and pointer to it */ int pindex = MAXPLEX; /* index in volume's plex list */ int detached = 0; /* don't give it to a volume */ current_plex = -1; /* forget the previous plex */ plexno = get_empty_plex(); /* allocate a plex */ plex = &PLEX[plexno]; /* and point to it */ plex->plexno = plexno; /* and back to the config */ for (parameter = 1; parameter < tokens; parameter++) { /* look at the other tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_detached: detached = 1; break; case kw_name: { int namedplexno; namedplexno = find_plex(token[++parameter], 0); /* find an existing plex with this name */ if (namedplexno >= 0) throw_rude_remark(EINVAL, "Duplicate plex %s", token[parameter]); } bcopy(token[parameter], /* put in the name */ plex->name, min(MAXPLEXNAME, strlen(token[parameter]))); break; case kw_org: /* plex organization */ switch (get_keyword(token[++parameter], &keyword_set)) { case kw_concat: plex->organization = plex_concat; break; case kw_striped: { int stripesize = sizespec(token[++parameter]); plex->organization = plex_striped; if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */ throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", plex->name, stripesize); else plex->stripesize = stripesize / DEV_BSIZE; break; } default: throw_rude_remark(EINVAL, "Invalid plex organization"); } if (((plex->organization == plex_striped) ) && (plex->stripesize == 0)) /* didn't specify a valid stripe size */ throw_rude_remark(EINVAL, "Need a stripe size parameter"); break; case kw_volume: plex->volno = find_volume(token[++parameter], 1); /* insert a pointer to the volume */ break; case kw_sd: /* add a subdisk */ { int sdno; sdno = find_subdisk(token[++parameter], 1); /* find a subdisk */ SD[sdno].plexoffset = sizespec(token[++parameter]); /* get the offset */ give_sd_to_plex(plexno, sdno); /* and insert it there */ break; } case kw_state: checkkernel(token[++parameter]); /* only for kernel use */ plex->state = PlexState(token[parameter]); /* set the state */ break; default: throw_rude_remark(EINVAL, "plex %s, invalid keyword: %s", plex->name, token[parameter]); } } if ((plex->volno < 0) /* we don't have a volume */ &&(!detached)) /* and we wouldn't object */ plex->volno = current_volume; if (plex->volno >= 0) pindex = give_plex_to_volume(plex->volno, plexno); /* Now tell the volume that it has this plex */ /* Does the plex have a name? If not, give it one */ if (plex->name[0] == '\0') { /* no name */ char plexsuffix[8]; /* form plex name suffix here */ /* Do we have a volume name? */ if (plex->volno >= 0) /* we have a volume */ strcpy(plex->name, /* take it from there */ VOL[plex->volno].name); else /* no way */ throw_rude_remark(EINVAL, "Unnamed plex is not associated with a volume"); sprintf(plexsuffix, ".p%d", pindex); /* form the suffix */ strcat(plex->name, plexsuffix); /* and add it to the name */ } /* Note the last plex we configured */ current_plex = plexno; if (plex->state == plex_unallocated) /* we haven't changed the state, */ plex->state = plex_init; /* we're initialized now */ } /* Handle a volume definition. * If we find an error, print a message, deallocate the nascent volume, and return */ void config_volume(void) { BROKEN_GDB; int parameter; int volno; struct volume *vol; /* collect volume info here */ int i; if (tokens < 2) /* not enough tokens */ throw_rude_remark(EINVAL, "Volume has no name"); current_volume = -1; /* forget the previous volume */ volno = find_volume(token[1], 1); /* allocate a volume to initialize */ vol = &VOL[volno]; /* and get a pointer */ for (parameter = 2; parameter < tokens; parameter++) { /* look at all tokens */ switch (get_keyword(token[parameter], &keyword_set)) { case kw_plex: { int plexno; /* index of this plex */ plexno = find_plex(token[++parameter], 1); /* find a plex */ if (plexno < 0) /* couldn't */ break; /* we've already had an error message */ plexno = my_plex(volno, plexno); /* does it already belong to us? */ if (plexno > 0) /* yes, shouldn't get it again */ throw_rude_remark(EINVAL, "Plex %s already belongs to volume %s", token[parameter], vol->name); else if (++vol->plexes > 8) /* another entry */ throw_rude_remark(EINVAL, "Too many plexes for volume %s", vol->name); vol->plex[vol->plexes - 1] = plexno; } break; case kw_readpol: switch (get_keyword(token[++parameter], &keyword_set)) { /* decide what to do */ case kw_round: vol->preferred_plex = ROUND_ROBIN_READPOL; /* default */ break; case kw_prefer: { int myplexno; /* index of this plex */ myplexno = find_plex(token[++parameter], 1); /* find a plex */ if (myplexno < 0) /* couldn't */ break; /* we've already had an error message */ myplexno = my_plex(volno, myplexno); /* does it already belong to us? */ if (myplexno > 0) /* yes */ vol->preferred_plex = myplexno; /* just note the index */ else if (++vol->plexes > 8) /* another entry */ throw_rude_remark(EINVAL, "Too many plexes"); else { /* space for the new plex */ vol->plex[vol->plexes - 1] = myplexno; /* add it to our list */ vol->preferred_plex = vol->plexes - 1; /* and note the index */ } } break; default: throw_rude_remark(EINVAL, "Invalid read policy"); } case kw_setupstate: vol->flags |= VF_CONFIG_SETUPSTATE; /* set the volume up later on */ break; case kw_state: checkkernel(token[++parameter]); /* must be a kernel user */ vol->state = VolState(token[parameter]); /* set the state */ break; /* XXX experimental ideas. These are not * documented, and will not be until I * decide they're worth keeping */ case kw_writethrough: /* set writethrough mode */ vol->flags |= VF_WRITETHROUGH; break; case kw_writeback: /* set writeback mode */ vol->flags &= ~VF_WRITETHROUGH; break; case kw_raw: vol->flags |= VF_RAW; /* raw volume (no label) */ break; default: throw_rude_remark(EINVAL, "volume %s, invalid keyword: %s", vol->name, token[parameter]); } } current_volume = volno; /* note last referred volume */ vol->devno = VINUMBDEV(volno, 0, 0, VINUM_VOLUME_TYPE); /* also note device number */ /* Before we can actually use the volume, we need * a volume label. We could start to fake one here, * but it will be a lot easier when we have some * to copy from the drives, so defer it until we * set up the configuration. XXX */ if (vol->state == volume_unallocated) vol->state = volume_down; /* now ready to bring up at the end */ /* Find out how big our volume is */ for (i = 0; i < vol->plexes; i++) vol->size = max(vol->size, PLEX[vol->plex[i]].length); } /* Parse a config entry. CARE! This destroys the original contents of the * config entry, which we don't really need after this. More specifically, it * places \0 characters at the end of each token. * * Return 0 if all is well, otherwise EINVAL */ int parse_config(char *cptr, struct keywordset *keyset) { BROKEN_GDB; int status; status = 0; /* until proven otherwise */ tokens = tokenize(cptr, token); /* chop up into tokens */ if (tokens <= 0) /* screwed up or empty line */ return tokens; /* give up */ if (token[0][0] == '#') /* comment line */ return 0; switch (get_keyword(token[0], keyset)) { /* decide what to do */ case kw_read: /* read config from a specified drive */ vinum_conf.flags |= VF_KERNELOP | VF_READING_CONFIG; /* kernel operation: reading config */ status = check_drive(token[1]); /* check the drive info */ vinum_conf.flags &= ~(VF_KERNELOP | VF_READING_CONFIG); if (status != 0) { char *msg = "Can't read configuration from %s"; if (status == ENODEV) msg = "No vinum configuration on %s"; throw_rude_remark(status, msg, token[1]); } updateconfig(VF_KERNELOP); /* update from kernel space */ break; case kw_drive: config_drive(); break; case kw_subdisk: config_subdisk(); break; case kw_plex: config_plex(); break; case kw_volume: config_volume(); break; /* Anything else is invalid in this context */ default: throw_rude_remark(EINVAL, /* should we die? */ "Invalid configuration information: %s", token[0]); } return status; } /* parse a line handed in from userland via ioctl. * This differs only by the error reporting mechanism: * we return the error indication in the reply to the * ioctl, so we need to set a global static pointer in * this file. This technique works because we have * ensured that configuration is performed in a single- * threaded manner */ int parse_user_config(char *cptr, struct keywordset *keyset) { BROKEN_GDB; int status; ioctl_reply = (struct _ioctl_reply *) cptr; status = parse_config(cptr, keyset); ioctl_reply = NULL; /* don't do this again */ return status; } /* Remove an object */ void remove(struct vinum_ioctl_msg *msg) { struct vinum_ioctl_msg message = *msg; /* make a copy to hand on */ ioctl_reply = (struct _ioctl_reply *) msg; /* reinstate the address to reply to */ ioctl_reply->error = 0; /* no error, */ ioctl_reply->msg[0] = '\0'; /* no message */ switch (message.type) { case drive_object: remove_drive_entry(message.index, message.force, message.recurse); updateconfig(0); return; case sd_object: remove_sd_entry(message.index, message.force, message.recurse); updateconfig(0); return; case plex_object: remove_plex_entry(message.index, message.force, message.recurse); updateconfig(0); return; case volume_object: remove_volume_entry(message.index, message.force, message.recurse); updateconfig(0); return; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); } } /* Remove a drive. */ void remove_drive_entry(int driveno, int force, int recurse) { struct drive *drive = &DRIVE[driveno]; if ((driveno > vinum_conf.drives_used) /* not a valid drive */ ||(drive->state == drive_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such drive"); } else if (drive->opencount > 0) { /* we have subdisks */ if (force) { /* do it at any cost */ int sdno; struct vinum_ioctl_msg sdmsg; for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { if ((SD[sdno].state != sd_unallocated) /* subdisk is allocated */ &&(SD[sdno].driveno == driveno)) { /* and it belongs to this drive */ sdmsg.type = sd_object; sdmsg.recurse = 1; sdmsg.force = force; remove(&sdmsg); /* remove the subdisk by force */ } } remove_drive(driveno); /* now remove it */ } else ioctl_reply->error = EBUSY; /* can't do that */ } else remove_drive(driveno); /* just remove it */ } /* remove a subdisk */ void remove_sd_entry(int sdno, int force, int recurse) { struct sd *sd = &SD[sdno]; if ((sdno > vinum_conf.subdisks_used) /* not a valid sd */ ||(sd->state == sd_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such subdisk"); } else if (sd->plexno >= 0) { /* we have a plex */ if (force) { /* do it at any cost */ struct plex *plex = &PLEX[sd->plexno]; /* point to our plex */ int mysdno; for (mysdno = 0; /* look for ourselves */ mysdno < plex->subdisks && &SD[plex->sdnos[mysdno]] != sd; mysdno++); if (mysdno == plex->subdisks) /* didn't find it */ throw_rude_remark(ENOENT, "plex %s does not contain subdisk %s", plex->name, sd->name); if (mysdno < (plex->subdisks - 1)) /* not the last subdisk */ bcopy(&plex->sdnos[mysdno + 1], &plex->sdnos[mysdno], (plex->subdisks - 1 - mysdno) * sizeof(int)); plex->subdisks--; /* removing a subdisk from a striped or * RAID-5 plex really tears the hell out * of the structure, and it needs to be * reinitialized */ if (plex->organization != plex_concat) /* not concatenated, */ set_plex_state(plex->plexno, plex_faulty, setstate_force); /* need to reinitialize */ rebuild_plex_unmappedlist(plex); /* and see what remains */ free_sd(sdno); } else ioctl_reply->error = EBUSY; /* can't do that */ } else free_sd(sdno); } /* remove a plex */ void remove_plex_entry(int plexno, int force, int recurse) { struct plex *plex = &PLEX[plexno]; int sdno; if ((plexno > vinum_conf.plexes_used) /* not a valid plex */ ||(plex->state == plex_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such plex"); } else if (plex->pid) { /* we're open */ ioctl_reply->error = EBUSY; /* no getting around that */ return; } if (plex->subdisks) { if (force) { /* do it anyway */ if (recurse) { /* remove all below */ for (sdno = 0; sdno < plex->subdisks; sdno++) free_sd(plex->sdnos[sdno]); /* free all subdisks */ } else { /* just tear them out */ for (sdno = 0; sdno < plex->subdisks; sdno++) SD[plex->sdnos[sdno]].plexno = -1; /* no plex any more */ } } else { /* can't do it without force */ ioctl_reply->error = EBUSY; /* can't do that */ return; } } if (plex->volno >= 0) { /* we are part of a volume */ /* XXX This should be more intelligent. We should * be able to remove a plex as long as the volume * does not lose any data, which is normally the * case when it has more than one plex. To do it * right we must compare the completeness of the * mapping of all the plexes in the volume */ if (force) { /* do it at any cost */ struct volume *vol = &VOL[plex->volno]; int myplexno; for (myplexno = 0; myplexno < vol->plexes; myplexno++) if (vol->plex[myplexno] == plexno) /* found it */ break; if (myplexno == vol->plexes) /* didn't find it. Huh? */ throw_rude_remark(ENOENT, "volume %s does not contain plex %s", vol->name, plex->name); if (myplexno < (vol->plexes - 1)) /* not the last plex in the list */ bcopy(&vol->plex[myplexno + 1], &vol->plex[myplexno], vol->plexes - 1 - myplexno); vol->plexes--; } else { ioctl_reply->error = EBUSY; /* can't do that */ return; } } free_plex(plexno); } /* remove a volume */ void remove_volume_entry(int volno, int force, int recurse) { struct volume *vol = &VOL[volno]; int plexno; if ((volno > vinum_conf.volumes_used) /* not a valid volume */ ||(vol->state == volume_unallocated)) { /* or nothing there */ ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "No such volume"); } else if (vol->opencount) /* we're open */ ioctl_reply->error = EBUSY; /* no getting around that */ else if (vol->plexes) { if (recurse && force) { /* remove all below */ struct vinum_ioctl_msg plexmsg; plexmsg.type = plex_object; plexmsg.recurse = 1; plexmsg.force = force; for (plexno = 0; plexno < vol->plexes; plexno++) { plexmsg.index = vol->plex[plexno]; /* plex number */ remove(&plexmsg); } free_volume(volno); } else ioctl_reply->error = EBUSY; /* can't do that */ } else free_volume(volno); } void update_sd_config(int sdno, int kernelstate) { if (!kernelstate) set_sd_state(sdno, sd_up, setstate_configuring | setstate_norecurse); } void update_plex_config(int plexno, int kernelstate) { int error = 0; int size; int sdno; struct plex *plex = &PLEX[plexno]; enum plexstate state = plex_up; /* state we want the plex in */ /* XXX Insert checks here for sparse plexes and volumes */ /* Check that our subdisks make sense. For * striped and RAID5 plexes, we need at least * two subdisks, and they must all be the same * size */ if (((plex->organization == plex_striped) ) && (plex->subdisks < 2)) { error = 1; printf("vinum: plex %s does not have at least 2 subdisks\n", plex->name); if (!kernelstate) set_plex_state(plexno, plex_down, setstate_force | setstate_configuring | setstate_norecurse); } size = 0; for (sdno = 0; sdno < plex->subdisks; sdno++) { if (((plex->organization == plex_striped) ) && (sdno > 0) && (SD[plex->sdnos[sdno]].sectors != SD[plex->sdnos[sdno - 1]].sectors)) { error = 1; printf("vinum: plex %s must have equal sized subdisks\n", plex->name); set_plex_state(plexno, plex_down, setstate_force | setstate_configuring | setstate_norecurse); } size += SD[plex->sdnos[sdno]].sectors; } if (plex->subdisks) { /* plex has subdisks, calculate size */ rebuild_plex_unmappedlist(plex); /* rebuild the unmapped list first */ plex->length = size; } else { /* no subdisks, */ plex->length = 0; /* no size */ state = plex_down; /* take it down */ } if (!(kernelstate || error)) set_plex_state(plexno, state, setstate_none | setstate_configuring | setstate_norecurse); } void update_volume_config(int volno, int kernelstate) { struct volume *vol = &VOL[volno]; struct plex *plex; int plexno; if (vol->state != volume_unallocated) /* Recalculate the size of the volume */ { vol->size = 0; for (plexno = 0; plexno < vol->plexes; plexno++) { plex = &PLEX[vol->plex[plexno]]; vol->size = max(plex->length, vol->size); /* maximum size */ plex->volplexno = plexno; /* note it in the plex */ } } if (!kernelstate) /* try to bring it up */ set_volume_state(volno, volume_up, setstate_configuring | setstate_norecurse); } /* Update the global configuration. * kernelstate is != 0 if we're reading in a config * from disk. In this case, we don't try to * bring the devices up, though we will bring * them down if there's some error which got * missed when writing to disk. */ void updateconfig(int kernelstate) { BROKEN_GDB; int sdno; int plexno; int volno; struct volume *vol; struct plex *plex; for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) update_sd_config(sdno, kernelstate); for (plexno = 0; plexno < vinum_conf.plexes_used; plexno++) update_plex_config(plexno, kernelstate); for (volno = 0; volno < vinum_conf.volumes_used; volno++) update_volume_config(volno, kernelstate); save_config(); } /* Start manual changes to the configuration and lock out * others who may wish to do so. * XXX why do we need this and lock_config too? */ int start_config(void) { int error; while ((vinum_conf.flags & VF_CONFIGURING) != 0) { vinum_conf.flags |= VF_WILL_CONFIGURE; if ((error = tsleep(&vinum_conf, PRIBIO | PCATCH, "vincfg", 0)) != 0) return error; } /* We need two flags here: VF_CONFIGURING * tells other processes to hold off (this * function), and VF_CONFIG_INCOMPLETE * tells the state change routines not to * propagate incrememntal state changes */ vinum_conf.flags |= VF_CONFIGURING | VF_CONFIG_INCOMPLETE; current_drive = -1; /* reset the defaults */ current_plex = -1; /* and the same for the last plex */ current_volume = -1; /* and the last volme */ return 0; } /* Update the config if update is 1, and unlock * it. We won't update the configuration if we * are called in a recursive loop via throw_rude_remark. */ void finish_config(int update) { vinum_conf.flags &= ~VF_CONFIG_INCOMPLETE; /* we've finished our config */ if (update) updateconfig(0); /* so update things */ else updateconfig(1); /* do some updates only */ vinum_conf.flags &= ~VF_CONFIGURING; /* and now other people can take a turn */ if ((vinum_conf.flags & VF_WILL_CONFIGURE) != 0) { vinum_conf.flags &= ~VF_WILL_CONFIGURE; wakeup(&vinum_conf); } } diff --git a/sys/dev/vinum/vinumext.h b/sys/dev/vinum/vinumext.h index 4b7d5a01d642..3b639180f17a 100644 --- a/sys/dev/vinum/vinumext.h +++ b/sys/dev/vinum/vinumext.h @@ -1,214 +1,204 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumext.h,v 1.14 1998/08/11 00:03:57 grog Exp grog $ + * $Id: vinumext.h,v 1.15 1998/09/29 05:17:56 grog Exp grog $ */ /* vinumext.h: external definitions */ extern struct _vinum_conf vinum_conf; /* configuration information */ #ifdef DEBUG extern debug; /* debug flags */ #endif #define CHECKALLOC(ptr, msg) \ if (ptr == NULL) \ { \ printf (msg); \ longjmp (command_fail, -1); \ } #ifndef KERNEL struct vnode; struct proc; #endif #ifdef KERNEL int give_sd_to_plex(int plexno, int sdno); int give_plex_to_volume(int volno, int plexno); int check_drive(char *); enum drive_label_info read_drive_label(struct drive *drive); int parse_config(char *, struct keywordset *); int parse_user_config(char *cptr, struct keywordset *keyset); u_int64_t sizespec(char *spec); int volume_index(struct volume *volume); int plex_index(struct plex *plex); int sd_index(struct sd *sd); int drive_index(struct drive *drive); int my_plex(int volno, int plexno); int my_sd(int plexno, int sdno); int get_empty_drive(void); int find_drive(const char *name, int create); int find_drive_by_dev(const char *devname, int create); int get_empty_sd(void); int find_subdisk(const char *name, int create); void free_sd(int sdno); void free_volume(int volno); int get_empty_plex(void); int find_plex(const char *name, int create); void free_plex(int plexno); int get_empty_volume(void); int find_volume(const char *name, int create); void config_subdisk(void); void config_plex(void); void config_volume(void); void config_drive(void); void updateconfig(int); void update_sd_config(int sdno, int kernelstate); void update_plex_config(int plexno, int kernelstate); void update_volume_config(int volno, int kernelstate); void update_config(void); void drive_io_done(struct buf *); int save_config(void); void write_config(char *, int); int start_config(void); void finish_config(int); void remove(struct vinum_ioctl_msg *msg); void remove_drive_entry(int driveno, int force, int recurse); void remove_sd_entry(int sdno, int force, int recurse); void remove_plex_entry(int plexno, int force, int recurse); void remove_volume_entry(int volno, int force, int recurse); void checkernel(char *); int open_drive(struct drive *, struct proc *); void close_drive(struct drive *drive); int driveio(struct drive *, void *, size_t, off_t, int); /* #define read_drive(a, b, c, d) driveio (a, b, c, d, B_READ) #define write_drive(a, b, c, d) driveio (a, b, c, d, B_WRITE) */ int set_drive_parms(struct drive *drive); int init_drive(struct drive *); /* void throw_rude_remark (int, struct _ioctl_reply *, char *, ...); XXX */ void throw_rude_remark(int, char *,...); int read_drive(struct drive *drive, void *buf, size_t length, off_t offset); int write_drive(struct drive *drive, void *buf, size_t length, off_t offset); void format_config(char *config, int len); void checkkernel(char *op); void free_drive(struct drive *drive); void down_drive(struct drive *drive); void remove_drive(int driveno); /* I/O */ d_open_t vinumopen; d_close_t vinumclose; d_strategy_t vinumstrategy; d_ioctl_t vinumioctl; d_dump_t vinumdump; d_psize_t vinumsize; d_read_t vinumread; d_write_t vinumwrite; int vinumstart(struct buf *bp, int reviveok); int launch_requests(struct request *rq, int reviveok); /* XXX Do we need this? */ int vinumpart(dev_t); -/* Memory allocation */ +#ifdef DEBUG +/* Memory allocation and request tracing */ void vinum_meminfo(caddr_t data); int vinum_mallocinfo(caddr_t data); +int vinum_rqinfo(caddr_t data); +#endif void expand_table(void **, int, int); void add_defective_region(struct plex *plex, off_t offset, size_t length); void add_unmapped_region(struct plex *plex, off_t offset, size_t length); void rebuild_plex_unmappedlist(struct plex *plex); struct request; struct rqgroup *allocrqg(struct request *rq, int elements); void deallocrqg(struct rqgroup *rqg); /* State transitions */ int set_drive_state(int driveno, enum drivestate state, int force); int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags); enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend); int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags); int set_volume_state(int volumeno, enum volumestate state, enum setstateflags flags); void get_volume_label(struct volume *vol, struct disklabel *lp); int write_volume_label(int); void start_object(struct vinum_ioctl_msg *); void stop_object(struct vinum_ioctl_msg *); void setstate(struct vinum_ioctl_msg *msg); void vinum_label(int); int vinum_writedisklabel(struct volume *, struct disklabel *); int initsd(int); int restart_plex(int plexno); int revive_block(int plexno); /* Auxiliary functions */ enum sdstates sdstatemap(struct plex *plex, int *sddowncount); enum volplexstate vpstate(struct plex *plex); #endif enum keyword get_keyword(char *, struct keywordset *); void listconfig(void); char *drive_state(enum drivestate); char *volume_state(enum volumestate); char *plex_state(enum plexstate); char *plex_org(enum plexorg); char *sd_state(enum sdstate); enum drivestate DriveState(char *text); enum sdstate SdState(char *text); enum plexstate PlexState(char *text); enum volumestate VolState(char *text); struct drive *validdrive(int driveno, struct _ioctl_reply *); struct sd *validsd(int sdno, struct _ioctl_reply *); struct plex *validplex(int plexno, struct _ioctl_reply *); struct volume *validvol(int volno, struct _ioctl_reply *); int tokenize(char *, char *[]); void resetstats(struct vinum_ioctl_msg *msg); /* Locking */ int lockvol(struct volume *vol); void unlockvol(struct volume *vol); int lockplex(struct plex *plex); void unlockplex(struct plex *plex); int lockrange(struct plex *plex, off_t first, off_t last); void unlockrange(struct plex *plex, off_t first, off_t last); int lock_config(void); void unlock_config(void); - -#ifdef DEBUG -#define expandrq(prq) \ -{ \ - expand_table ((void **) &prq->rqe, \ - prq->requests * sizeof (struct rqelement), \ - (prq->requests + RQELTS) * sizeof (struct rqelement) ); \ - bzero (&prq->rqe [prq->requests], RQELTS * sizeof (struct rqelement)); \ - prq->rqcount += RQELTS; \ - } -#else -void expandrq(struct plexrq *); -#endif diff --git a/sys/dev/vinum/vinuminterrupt.c b/sys/dev/vinum/vinuminterrupt.c index e7eb034faf4b..1557cfe69d3e 100644 --- a/sys/dev/vinum/vinuminterrupt.c +++ b/sys/dev/vinum/vinuminterrupt.c @@ -1,190 +1,194 @@ /* interrupt.c: bottom half of the driver */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: interrupt.c,v 1.1 1998/08/13 06:12:27 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" #include #include void complete_raid5_write(struct rqelement *); void freerq(struct request *rq); void free_rqg(struct rqgroup *rqg); void complete_rqe(struct buf *bp); void sdio_done(struct buf *bp); /* Take a completed buffer, transfer the data back if * it's a read, and complete the high-level request * if this is the last subrequest. * * The bp parameter is in fact a struct rqelement, which * includes a couple of extras at the end. */ void complete_rqe(struct buf *bp) { BROKEN_GDB; struct rqelement *rqe; struct request *rq; struct rqgroup *rqg; struct buf *ubp; /* user buffer */ rqe = (struct rqelement *) bp; /* point to the element element that completed */ rqg = rqe->rqg; /* and the request group */ rq = rqg->rq; /* and the complete request */ + ubp = rq->bp; /* user buffer */ +#ifdef DEBUG + if (debug & DEBUG_LASTREQS) + logrq(loginfo_iodone, rqe, ubp); +#endif if ((bp->b_flags & B_ERROR) != 0) { /* transfer in error */ if (bp->b_error != 0) /* did it return a number? */ rq->error = bp->b_error; /* yes, put it in. */ else if (rq->error == 0) /* no: do we have one already? */ rq->error = EIO; /* no: catchall "I/O error" */ if (rq->error == EIO) /* I/O error, */ - set_sd_state(rqe->sdno, sd_crashed, setstate_force); /* take the subdisk down */ + set_sd_state(rqe->sdno, sd_crashed, setstate_force | setstate_noupdate); /* take the subdisk down */ } /* Now update the statistics */ if (bp->b_flags & B_READ) { /* read operation */ DRIVE[rqe->driveno].reads++; DRIVE[rqe->driveno].bytes_read += bp->b_bcount; SD[rqe->sdno].reads++; SD[rqe->sdno].bytes_read += bp->b_bcount; PLEX[rqe->rqg->plexno].reads++; PLEX[rqe->rqg->plexno].bytes_read += bp->b_bcount; } else { /* write operation */ DRIVE[rqe->driveno].writes++; DRIVE[rqe->driveno].bytes_written += bp->b_bcount; SD[rqe->sdno].writes++; SD[rqe->sdno].bytes_written += bp->b_bcount; PLEX[rqe->rqg->plexno].writes++; PLEX[rqe->rqg->plexno].bytes_written += bp->b_bcount; } - ubp = rq->bp; /* user buffer */ rqg->active--; /* one less request active */ if (rqg->active == 0) /* request group finished, */ rq->active--; /* one less */ if (rq->active == 0) { /* request finished, */ #if DEBUG - if (debug & 4) { + if (debug & DEBUG_RESID) { if (ubp->b_resid != 0) /* still something to transfer? */ Debugger("resid"); { int i; for (i = 0; i < ubp->b_bcount; i += 512) /* XXX debug */ if (((char *) ubp->b_data)[i] != '<') { /* and not what we expected */ printf("At 0x%x (offset 0x%x): '%c' (0x%x)\n", (int) (&((char *) ubp->b_data)[i]), i, ((char *) ubp->b_data)[i], ((char *) ubp->b_data)[i]); Debugger("complete_request checksum"); } } } #endif if (rq->error) { /* did we have an error? */ ubp->b_flags |= B_ERROR; /* yes, propagate to user */ ubp->b_error = rq->error; } else ubp->b_resid = 0; /* completed our transfer */ if (rq->isplex == 0) /* volume request, */ VOL[rq->volplex.volno].active--; /* another request finished */ biodone(ubp); /* top level buffer completed */ freerq(rq); /* return the request storage */ } } /* Free a request block and anything hanging off it */ void freerq(struct request *rq) { BROKEN_GDB; struct rqgroup *rqg; struct rqgroup *nrqg; /* next in chain */ int rqno; for (rqg = rq->rqg; rqg != NULL; rqg = nrqg) { /* through the whole request chain */ for (rqno = 0; rqno < rqg->count; rqno++) if ((rqg->rqe[rqno].flags & XFR_MALLOCED) /* data buffer was malloced, */ &&rqg->rqe[rqno].b.b_data) /* and the allocation succeeded */ Free(rqg->rqe[rqno].b.b_data); /* free it */ nrqg = rqg->next; /* note the next one */ Free(rqg); /* and free this one */ } Free(rq); /* free the request itself */ } void free_rqg(struct rqgroup *rqg) { if ((rqg->flags & XFR_GROUPOP) /* RAID 5 request */ &&(rqg->rqe) /* got a buffer structure */ &&(rqg->rqe->b.b_data)) /* and it has a buffer allocated */ Free(rqg->rqe->b.b_data); /* free it */ } /* I/O on subdisk completed */ void sdio_done(struct buf *bp) { struct sdbuf *sbp; sbp = (struct sdbuf *) bp; if (sbp->b.b_flags & B_ERROR) { /* had an error */ bp->b_flags |= B_ERROR; bp->b_error = sbp->b.b_error; } bp->b_resid = sbp->b.b_resid; biodone(sbp->bp); /* complete the caller's I/O */ /* Now update the statistics */ if (bp->b_flags & B_READ) { /* read operation */ DRIVE[sbp->driveno].reads++; DRIVE[sbp->driveno].bytes_read += bp->b_bcount; SD[sbp->sdno].reads++; SD[sbp->sdno].bytes_read += bp->b_bcount; } else { /* write operation */ DRIVE[sbp->driveno].writes++; DRIVE[sbp->driveno].bytes_written += bp->b_bcount; SD[sbp->sdno].writes++; SD[sbp->sdno].bytes_written += bp->b_bcount; } Free(sbp); } diff --git a/sys/dev/vinum/vinumio.h b/sys/dev/vinum/vinumio.h index be79528a6db8..b99bd4217846 100644 --- a/sys/dev/vinum/vinumio.h +++ b/sys/dev/vinum/vinumio.h @@ -1,132 +1,141 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: vinumio.h,v 1.10 1998/08/10 05:46:19 grog Exp grog $ */ +#ifdef DEBUG +#define MAX_IOCTL_REPLY 4096 +#else #define MAX_IOCTL_REPLY 256 +#endif + #define L 'F' /* ID letter of our ioctls */ /* VINUM_CREATE returns a buffer of this kind */ struct _ioctl_reply { int error; char msg[MAX_IOCTL_REPLY]; }; /* ioctl requests */ #define BUFSIZE 1024 /* size of buffer, including continuations */ #define VINUM_CREATE _IOC(IOC_IN | IOC_OUT, L, 64, BUFSIZE) /* configure vinum */ #define VINUM_GETCONFIG _IOR(L, 65, struct _vinum_conf) /* get global config */ #define VINUM_DRIVECONFIG _IOWR(L, 66, struct drive) /* get drive config */ #define VINUM_SDCONFIG _IOWR(L, 67, struct sd) /* get subdisk config */ #define VINUM_PLEXCONFIG _IOWR(L, 68, struct plex) /* get plex config */ #define VINUM_VOLCONFIG _IOWR(L, 69, struct volume) /* get volume config */ #define VINUM_PLEXSDCONFIG _IOWR(L, 70, struct sd) /* get sd config for plex (plex, sdno) */ #define VINUM_GETFREELIST _IOWR(L, 71, struct drive_freelist) /* get freelist element (drive, fe) */ #define VINUM_SAVECONFIG _IOC(0, L, 72, 0) /* release locks, update, write config to disk */ #define VINUM_RESETCONFIG _IOC(0, L, 73, 0) /* trash config on disk */ #define VINUM_INIT _IOC(0, L, 74, 0) /* read config from disk */ #ifdef DEBUG struct debuginfo { int changeit; int param; }; #define VINUM_DEBUG _IOWR(L, 75, struct debuginfo) /* call the debugger from ioctl () */ #endif enum objecttype { drive_object, sd_object, plex_object, volume_object, invalid_object }; /* Start an object. Pass two integers: * msg [0] index in vinum_conf. * msg [1] type of object (see below) * * Return ioctl_reply */ #define VINUM_SETSTATE _IOC(IOC_IN | IOC_OUT, L, 76, MAX_IOCTL_REPLY) /* start an object */ /* The state to set with VINUM_SETSTATE. Since * each object has a different set of states, we * need to translate later */ enum objectstate { object_down, object_initializing, object_up }; /* This structure is used for modifying objects * (VINUM_SETSTATE, VINUM_REMOVE, VINUM_RESETSTATS, VINUM_ATTACH, * VINUM_DETACH, VINUM_REPLACE */ struct vinum_ioctl_msg { int index; enum objecttype type; enum objectstate state; /* state to set (VINUM_SETSTATE) */ int force; /* do it even if it doesn't make sense */ int recurse; /* recurse (VINUM_REMOVE) */ int otherobject; /* superordinate object (attach), * replacement object (replace) */ int rename; /* rename object (attach) */ int64_t offset; /* offset of subdisk (for attach) */ }; #define VINUM_RELEASECONFIG _IOC(0, L, 77, 0) /* release locks and write config to disk */ #define VINUM_STARTCONFIG _IOC(0, L, 78, 0) /* start a configuration operation */ #define VINUM_MEMINFO _IOR(L, 79, struct meminfo) /* get memory usage summary */ #define VINUM_MALLOCINFO _IOWR(L, 80, struct mc) /* get specific malloc information [i] */ #define VINUM_LABEL _IOC(IOC_IN | IOC_OUT, L, 81, MAX_IOCTL_REPLY) /* label a volume */ #define VINUM_INITSD _IOW(L, 82, int) /* initialize a subdisk */ #define VINUM_REMOVE _IOC(IOC_IN | IOC_OUT, L, 83, MAX_IOCTL_REPLY) /* remove an object */ #define VINUM_GETUNMAPPED _IOWR(L, 84, struct plexregion) /* get unmapped element (plex, re) */ #define VINUM_GETDEFECTIVE _IOWR(L, 85, struct plexregion) /* get defective element (plex, re) */ #define VINUM_RESETSTATS _IOC(IOC_IN | IOC_OUT, L, 86, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_ATTACH _IOC(IOC_IN | IOC_OUT, L, 87, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_DETACH _IOC(IOC_IN | IOC_OUT, L, 88, MAX_IOCTL_REPLY) /* reset object stats */ struct vinum_rename_msg { int index; int recurse; /* rename subordinate objects too */ enum objecttype type; char newname[MAXNAME]; /* new name to give to object */ }; #define VINUM_RENAME _IOC(IOC_IN | IOC_OUT, L, 89, MAX_IOCTL_REPLY) /* reset object stats */ #define VINUM_REPLACE _IOC(IOC_IN | IOC_OUT, L, 90, MAX_IOCTL_REPLY) /* reset object stats */ + +#ifdef DEBUG +#define VINUM_RQINFO _IOWR(L, 91, struct rqinfo) /* get request info [i] from trace buffer */ +#endif diff --git a/sys/dev/vinum/vinumioctl.c b/sys/dev/vinum/vinumioctl.c index 6dbe3c6bf4d6..fd91f79a418f 100644 --- a/sys/dev/vinum/vinumioctl.c +++ b/sys/dev/vinum/vinumioctl.c @@ -1,787 +1,795 @@ /* XXX replace all the checks on object validity with * calls to valid */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumioctl.c,v 1.1 1998/08/14 08:46:10 grog Exp grog $ + * $Id: vinumioctl.c,v 1.3 1998/09/29 05:26:37 grog Exp grog $ */ #define STATIC /* nothing while we're testing XXX */ #define REALLYKERNEL #include "vinumhdr.h" #include "sys/sysproto.h" /* for sync(2) */ #ifdef DEBUG #include +#include "request.h" #endif jmp_buf command_fail; /* return on a failed command */ #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ int setjmp(jmp_buf); void longjmp(jmp_buf, int); #endif /* pointer to ioctl p parameter, to save passing it around */ struct proc *myproc; int vinum_inactive(void); void free_vinum(int); void attachobject(struct vinum_ioctl_msg *); void detachobject(struct vinum_ioctl_msg *); void renameobject(struct vinum_rename_msg *); void replaceobject(struct vinum_ioctl_msg *); /* ioctl routine */ int vinumioctl(dev_t dev, #if __FreeBSD__ >= 3 u_long cmd, #else int cmd, #endif caddr_t data, int flag, struct proc *p) { BROKEN_GDB; unsigned int objno; int error = 0; struct volume *vol; unsigned int index; /* for transferring config info */ unsigned int sdno; /* for transferring config info */ int fe; /* free list element number */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* struct to return */ struct devcode *device = (struct devcode *) &dev; /* First, decide what we're looking at */ switch (device->type) { case VINUM_SUPERDEV_TYPE: myproc = p; /* save pointer to process */ ioctl_reply = (struct _ioctl_reply *) data; /* save the address to reply to */ error = setjmp(command_fail); /* come back here on error */ if (error) /* bombed out */ return 0; /* the reply will contain meaningful info */ switch (cmd) { - /* XXX #ifdef DEBUG */ +#ifdef DEBUG case VINUM_DEBUG: - boothowto |= RB_GDB; /* serial debug line */ if (((struct debuginfo *) data)->changeit) /* change debug settings */ debug = (((struct debuginfo *) data)->param); - else + else { + if (debug & DEBUG_REMOTEGDB) + boothowto |= RB_GDB; /* serial debug line */ + else + boothowto &= ~RB_GDB; /* local ddb */ Debugger("vinum debug"); + } ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; - /* XXX #endif */ +#endif case VINUM_CREATE: /* create a vinum object */ error = lock_config(); /* get the config for us alone */ if (error) /* can't do it, */ return error; /* give up */ error = setjmp(command_fail); /* come back here on error */ if (error == 0) { /* first time, */ parse_user_config((char *) data, &keyword_set); /* update the config */ ioctl_reply->error = 0; /* no error if we make it here */ } else if (ioctl_reply->error == 0) { /* longjmp, but no error status */ ioctl_reply->error = EINVAL; /* note that something's up */ ioctl_reply->msg[0] = '\0'; /* no message? */ } unlock_config(); return 0; /* must be 0 to return the real error info */ case VINUM_GETCONFIG: /* get the configuration information */ bcopy(&vinum_conf, data, sizeof(vinum_conf)); return 0; /* start configuring the subsystem */ case VINUM_STARTCONFIG: return start_config(); /* just lock it */ /* Move the individual parts of the config to user space. * Specify the index of the object in the first word of data, * and return the object there */ case VINUM_DRIVECONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.drives_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&DRIVE[index], data, sizeof(struct drive)); /* copy the config item out */ return 0; case VINUM_SDCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.subdisks_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&SD[index], data, sizeof(struct sd)); /* copy the config item out */ return 0; case VINUM_PLEXCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.plexes_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&PLEX[index], data, sizeof(struct plex)); /* copy the config item out */ return 0; case VINUM_VOLCONFIG: index = *(int *) data; /* get the index */ if (index >= (unsigned) vinum_conf.volumes_used) /* can't do it */ return EFAULT; /* bang */ bcopy(&VOL[index], data, sizeof(struct volume)); /* copy the config item out */ return 0; case VINUM_PLEXSDCONFIG: index = *(int *) data; /* get the plex index */ sdno = ((int *) data)[1]; /* and the sd index */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(sdno >= PLEX[index].subdisks)) /* or it doesn't have this many subdisks */ return EFAULT; /* bang */ bcopy(&SD[PLEX[index].sdnos[sdno]], /* copy the config item out */ data, sizeof(struct sd)); return 0; case VINUM_SAVECONFIG: if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */ finish_config(1); /* finish the configuration and update it */ error = save_config(); /* save configuration to disk */ } else error = EINVAL; /* queue up for this one, please */ return error; case VINUM_RELEASECONFIG: /* release the config */ if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */ finish_config(0); /* finish the configuration, don't change it */ error = save_config(); /* save configuration to disk */ } else error = EINVAL; /* release what config? */ return error; case VINUM_INIT: ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; case VINUM_RESETCONFIG: if (vinum_inactive() && (vinum_conf.opencount < 2)) { /* if we're not active */ /* Note the open count. We may be called from v, so we'll be open. * Keep the count so we don't underflow */ int oc = vinum_conf.opencount; free_vinum(1); /* clean up everything */ printf("vinum: CONFIGURATION OBLITERATED\n"); vinum_conf.opencount = oc; ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */ ioctl_reply->error = 0; return 0; } return EBUSY; case VINUM_SETSTATE: setstate((struct vinum_ioctl_msg *) data); /* set an object state */ return 0; case VINUM_MEMINFO: vinum_meminfo(data); return 0; case VINUM_MALLOCINFO: return vinum_mallocinfo(data); + case VINUM_RQINFO: + return vinum_rqinfo(data); + case VINUM_LABEL: /* label a volume */ ioctl_reply->error = write_volume_label(*(int *) data); /* index of the volume to label */ ioctl_reply->msg[0] = '\0'; /* no message */ return 0; case VINUM_REMOVE: remove((struct vinum_ioctl_msg *) data); /* remove an object */ return 0; case VINUM_GETFREELIST: /* get a drive free list element */ index = *(int *) data; /* get the drive index */ fe = ((int *) data)[1]; /* and the free list element */ if ((index >= (unsigned) vinum_conf.drives_used) /* plex doesn't exist */ ||(DRIVE[index].state == drive_unallocated)) return ENODEV; if (fe >= DRIVE[index].freelist_entries) /* no such entry */ return ENOENT; bcopy(&DRIVE[index].freelist[fe], data, sizeof(struct drive_freelist)); return 0; case VINUM_GETDEFECTIVE: /* get a plex defective area element */ index = *(int *) data; /* get the plex index */ fe = ((int *) data)[1]; /* and the region number */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(PLEX[index].state == plex_unallocated)) return ENODEV; if (fe >= PLEX[index].defective_regions) /* no such entry */ return ENOENT; bcopy(&PLEX[index].defective_region[fe], data, sizeof(struct plexregion)); return 0; case VINUM_GETUNMAPPED: /* get a plex unmapped area element */ index = *(int *) data; /* get the plex index */ fe = ((int *) data)[1]; /* and the region number */ if ((index >= (unsigned) vinum_conf.plexes_used) /* plex doesn't exist */ ||(PLEX[index].state == plex_unallocated)) return ENODEV; if (fe >= PLEX[index].unmapped_regions) /* no such entry */ return ENOENT; bcopy(&PLEX[index].unmapped_region[fe], data, sizeof(struct plexregion)); return 0; case VINUM_RESETSTATS: resetstats((struct vinum_ioctl_msg *) data); /* reset object stats */ return 0; /* attach an object to a superordinate object */ case VINUM_ATTACH: attachobject((struct vinum_ioctl_msg *) data); return 0; /* detach an object from a superordinate object */ case VINUM_DETACH: detachobject((struct vinum_ioctl_msg *) data); return 0; /* rename an object */ case VINUM_RENAME: renameobject((struct vinum_rename_msg *) data); return 0; /* replace an object */ case VINUM_REPLACE: replaceobject((struct vinum_ioctl_msg *) data); return 0; default: /* FALLTHROUGH */ } default: #if __FreeBSD__>=3 printf("vinumioctl: type %d, sd %d, plex %d, major %x, volume %d, command %lx\n", device->type, device->sd, device->plex, device->major, device->volume, cmd); /* XXX */ #else printf("vinumioctl: type %d, sd %d, plex %d, major %x, volume %d, command %x\n", device->type, device->sd, device->plex, device->major, device->volume, cmd); /* XXX */ #endif return EINVAL; case VINUM_DRIVE_TYPE: case VINUM_PLEX_TYPE: return EAGAIN; /* try again next week */ case VINUM_SD_TYPE: objno = SDNO(dev); switch (cmd) { case VINUM_INITSD: /* initialize subdisk */ return initsd(objno); default: return EINVAL; } break; case VINUM_VOLUME_TYPE: objno = VOLNO(dev); if ((unsigned) objno >= (unsigned) vinum_conf.volumes_used) /* not a valid volume */ return ENXIO; vol = &VOL[objno]; if (vol->state != volume_up) /* not up, */ return EIO; /* I/O error */ switch (cmd) { case DIOCGDINFO: /* get disk label */ get_volume_label(vol, (struct disklabel *) data); break; /* Care! DIOCGPART returns *pointers* to * the caller, so we need to store this crap as well. * And yes, we need it. */ case DIOCGPART: /* get partition information */ get_volume_label(vol, &vol->label); ((struct partinfo *) data)->disklab = &vol->label; ((struct partinfo *) data)->part = &vol->label.d_partitions[0]; break; /* We don't have this stuff on hardware, * so just pretend to do it so that * utilities don't get upset. */ case DIOCWDINFO: /* write partition info */ case DIOCSDINFO: /* set partition info */ return 0; /* not a titty */ case DIOCWLABEL: /* set or reset label writeable */ if ((flag & FWRITE) == 0) /* not writeable? */ return EACCES; /* no, die */ if (*(int *) data != 0) /* set it? */ vol->flags |= VF_WLABEL; /* yes */ else vol->flags &= ~VF_WLABEL; /* no, reset */ break; default: return ENOTTY; /* not my kind of ioctl */ } break; } return 0; /* XXX */ } /* The following four functions check the supplied * object index and return a pointer to the object * if it exists. Otherwise they longjump out via * throw_rude_remark */ struct drive * validdrive(int driveno, struct _ioctl_reply *reply) { if ((driveno < vinum_conf.drives_used) && (DRIVE[driveno].state != drive_unallocated)) return &DRIVE[driveno]; strcpy(reply->msg, "No such drive"); reply->error = ENOENT; return NULL; } struct sd * validsd(int sdno, struct _ioctl_reply *reply) { if ((sdno < vinum_conf.subdisks_used) && (SD[sdno].state != sd_unallocated)) return &SD[sdno]; strcpy(reply->msg, "No such subdisk"); reply->error = ENOENT; return NULL; } struct plex * validplex(int plexno, struct _ioctl_reply *reply) { if ((plexno < vinum_conf.plexes_used) && (PLEX[plexno].state != plex_unallocated)) return &PLEX[plexno]; strcpy(reply->msg, "No such plex"); reply->error = ENOENT; return NULL; } struct volume * validvol(int volno, struct _ioctl_reply *reply) { if ((volno < vinum_conf.volumes_used) && (VOL[volno].state != volume_unallocated)) return &VOL[volno]; strcpy(reply->msg, "No such volume"); reply->error = ENOENT; return NULL; } /* reset an object's stats */ void resetstats(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; switch (msg->type) { case drive_object: if (msg->index < vinum_conf.drives_used) { struct drive *drive = &DRIVE[msg->index]; if (drive->state != drive_unallocated) { drive->reads = 0; /* number of reads on this drive */ drive->writes = 0; /* number of writes on this drive */ drive->bytes_read = 0; /* number of bytes read */ drive->bytes_written = 0; /* number of bytes written */ reply->error = 0; return; } reply->error = EINVAL; return; } case sd_object: if (msg->index < vinum_conf.subdisks_used) { struct sd *sd = &SD[msg->index]; if (sd->state != sd_unallocated) { sd->reads = 0; /* number of reads on this subdisk */ sd->writes = 0; /* number of writes on this subdisk */ sd->bytes_read = 0; /* number of bytes read */ sd->bytes_written = 0; /* number of bytes written */ reply->error = 0; return; } reply->error = EINVAL; return; } break; case plex_object: if (msg->index < vinum_conf.plexes_used) { struct plex *plex = &PLEX[msg->index]; if (plex->state != plex_unallocated) { plex->reads = 0; plex->writes = 0; /* number of writes on this plex */ plex->bytes_read = 0; /* number of bytes read */ plex->bytes_written = 0; /* number of bytes written */ plex->multiblock = 0; /* requests that needed more than one block */ plex->multistripe = 0; /* requests that needed more than one stripe */ reply->error = 0; return; } reply->error = EINVAL; return; } break; case volume_object: if (msg->index < vinum_conf.volumes_used) { struct volume *vol = &VOL[msg->index]; if (vol->state != volume_unallocated) { vol->bytes_read = 0; /* number of bytes read */ vol->bytes_written = 0; /* number of bytes written */ vol->reads = 0; /* number of reads on this volume */ vol->writes = 0; /* number of writes on this volume */ vol->recovered_reads = 0; /* reads recovered from another plex */ reply->error = 0; return; } reply->error = EINVAL; return; } case invalid_object: /* can't get this */ reply->error = EINVAL; return; } } /* attach an object to a superior object */ void attachobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct sd *sd; struct plex *plex; struct volume *vol; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ case volume_object: /* nor a volume */ case invalid_object: /* "this can't happen" */ reply->error = EINVAL; reply->msg[0] = '\0'; /* vinum(8) doesn't do this */ return; case sd_object: sd = validsd(msg->index, reply); if (sd == NULL) /* not a valid subdisk */ return; plex = validplex(msg->otherobject, reply); if (plex) { if (sd->plexno >= 0) { /* already belong to a plex */ reply->error = EBUSY; /* no message, the user should check */ reply->msg[0] = '\0'; return; } sd->plexoffset = msg->offset; /* this is where we want it */ set_sd_state(sd->sdno, sd_stale, setstate_force); /* make sure it's stale */ give_sd_to_plex(plex->plexno, sd->sdno); /* and give it to the plex */ update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } break; case plex_object: plex = validplex(msg->index, reply); /* get plex */ if (plex == NULL) return; if (plex->organization != plex_concat) { /* can't attach to striped and raid-5 */ reply->error = EINVAL; /* no message, the user should check */ reply->msg[0] = '\0'; return; } vol = validvol(msg->otherobject, reply); /* and volume information */ if (vol) { if ((vol->plexes == MAXPLEX) /* we have too many already */ ||(plex->volno >= 0)) { /* or the plex has an owner */ reply->error = EINVAL; /* no message, the user should check */ reply->msg[0] = '\0'; return; } set_plex_state(plex->plexno, plex_down, setstate_force); /* make sure it's down */ give_plex_to_volume(msg->otherobject, msg->index); /* and give it to the volume */ update_plex_config(plex->plexno, 0); save_config(); if (plex->state == plex_reviving) reply->error = EAGAIN; /* need to revive it */ else reply->error = 0; } } } /* detach an object from a superior object */ void detachobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct sd *sd; struct plex *plex; struct volume *vol; int sdno; int plexno; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ case volume_object: /* nor a volume */ case invalid_object: /* "this can't happen" */ reply->error = EINVAL; reply->msg[0] = '\0'; /* vinum(8) doesn't do this */ return; case sd_object: sd = validsd(msg->index, reply); if (sd == NULL) return; if (sd->plexno < 0) { /* doesn't belong to a plex */ reply->error = ENOENT; strcpy(reply->msg, "Subdisk is not attached"); return; } else { /* valid plex number */ plex = &PLEX[sd->plexno]; if ((!msg->force) /* don't force things */ &&((plex->state == plex_up) /* and the plex is up */ ||((plex->state == plex_flaky) && sd->state == sd_up))) { /* or flaky with this sd up */ reply->error = EBUSY; /* we need this sd */ reply->msg[0] = '\0'; return; } sd->plexno = -1; /* anonymous sd */ if (plex->subdisks == 1) { /* this was the only subdisk */ Free(plex->sdnos); /* free the subdisk array */ plex->sdnos = NULL; /* and note the fact */ plex->subdisks_allocated = 0; /* no subdisk space */ } else { for (sdno = 0; sdno < plex->subdisks; sdno++) { if (plex->sdnos[sdno] == msg->index) /* found our subdisk */ break; } if (sdno < (plex->subdisks - 1)) /* not the last one, compact */ bcopy(&plex->sdnos[sdno + 1], &plex->sdnos[sdno], (plex->subdisks - 1 - sdno) * sizeof(int)); } plex->subdisks--; rebuild_plex_unmappedlist(plex); /* rebuild the unmapped list */ if (!bcmp(plex->name, sd->name, strlen(plex->name))) { /* this subdisk is named after the plex */ bcopy(sd->name, &sd->name[3], min(strlen(sd->name), MAXSDNAME - 3)); bcopy("ex-", sd->name, 3); sd->name[MAXSDNAME - 1] = '\0'; } update_plex_config(plex->plexno, 0); if ((plex->organization == plex_striped) /* we've just mutilated our plex, */ ||(plex->organization == plex_striped)) /* the data no longer matches */ set_plex_state(plex->plexno, plex_down, setstate_force | setstate_configuring); update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } return; case plex_object: plex = validplex(msg->index, reply); /* get plex */ if (plex == NULL) return; if (plex->volno >= 0) { int volno = plex->volno; vol = &VOL[volno]; if ((!msg->force) /* don't force things */ &&((vol->state == volume_up) /* and the volume is up */ &&(vol->plexes == 1))) { /* and this is the last plex */ /* XXX As elsewhere, check whether we will lose * mapping by removing this plex */ reply->error = EBUSY; /* we need this plex */ reply->msg[0] = '\0'; return; } plex->volno = -1; /* anonymous plex */ for (plexno = 0; plexno < vol->plexes; plexno++) { if (vol->plex[plexno] == msg->index) /* found our plex */ break; } if (plexno < (vol->plexes - 1)) /* not the last one, compact */ bcopy(&vol[plexno + 1], &vol[plexno], (vol->plexes - 1 - plexno) * sizeof(int)); vol->plexes--; if (!bcmp(vol->name, plex->name, strlen(vol->name))) { /* this plex is named after the volume */ /* First, check if the subdisks are the same */ if (msg->recurse) { int sdno; for (sdno = 0; sdno < plex->subdisks; sdno++) { struct sd *sd = &SD[plex->sdnos[sdno]]; if (!bcmp(plex->name, sd->name, strlen(plex->name))) { /* subdisk is named after the plex */ bcopy(sd->name, &sd->name[3], min(strlen(sd->name), MAXSDNAME - 3)); bcopy("ex-", sd->name, 3); sd->name[MAXSDNAME - 1] = '\0'; } } } bcopy(plex->name, &plex->name[3], min(strlen(plex->name), MAXPLEXNAME - 3)); bcopy("ex-", plex->name, 3); plex->name[MAXPLEXNAME - 1] = '\0'; } update_plex_config(plex->plexno, 0); update_volume_config(volno, 0); save_config(); reply->error = 0; } else { reply->error = ENOENT; strcpy(reply->msg, "Plex is not attached"); } } } void renameobject(struct vinum_rename_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; struct drive *drive; struct sd *sd; struct plex *plex; struct volume *vol; switch (msg->type) { case drive_object: /* you can't attach a drive to anything */ if (find_drive(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } drive = validdrive(msg->index, reply); if (drive) { bcopy(msg->newname, drive->label.name, MAXDRIVENAME); save_config(); reply->error = 0; } return; case sd_object: /* you can't attach a subdisk to anything */ if (find_subdisk(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } sd = validsd(msg->index, reply); if (sd) { bcopy(msg->newname, sd->name, MAXSDNAME); update_sd_config(sd->sdno, 0); save_config(); reply->error = 0; } return; case plex_object: /* you can't attach a plex to anything */ if (find_plex(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } plex = validplex(msg->index, reply); if (plex) { bcopy(msg->newname, plex->name, MAXPLEXNAME); update_plex_config(plex->plexno, 0); save_config(); reply->error = 0; } return; case volume_object: /* you can't attach a volume to anything */ if (find_volume(msg->newname, 0) >= 0) { /* we have that name already, */ reply->error = EEXIST; reply->msg[0] = '\0'; return; } vol = validvol(msg->index, reply); if (vol) { bcopy(msg->newname, vol->name, MAXVOLNAME); update_volume_config(msg->index, 0); save_config(); reply->error = 0; } return; case invalid_object: reply->error = EINVAL; reply->msg[0] = '\0'; } } /* Replace one object with another */ void replaceobject(struct vinum_ioctl_msg *msg) { struct _ioctl_reply *reply = (struct _ioctl_reply *) msg; reply->error = ENODEV; /* until I know how to do this */ strcpy(reply->msg, "replace not implemented yet"); /* save_config (); */ } diff --git a/sys/dev/vinum/vinumkw.h b/sys/dev/vinum/vinumkw.h index 1a81f37656f4..597d160ad2b1 100644 --- a/sys/dev/vinum/vinumkw.h +++ b/sys/dev/vinum/vinumkw.h @@ -1,120 +1,120 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: vinumkw.h,v 1.7 1998/08/07 02:35:51 grog Exp grog $ + * $Id: vinumkw.h,v 1.8 1998/09/29 05:17:39 grog Exp grog $ */ /* Command keywords that vinum knows. These include both user-level * and kernel-level stuff */ /* Our complete vocabulary. The names of the commands are * the same as the identifier without the kw_ at the beginning * (i.e. kw_create defines the "create" keyword). Preprocessor * magic in parser.c does the rest. */ enum keyword { kw_create, kw_modify, kw_list, kw_l = kw_list, kw_ld, /* list drive */ kw_ls, /* list subdisk */ kw_lp, /* list plex */ kw_lv, /* list volume */ kw_set, kw_rm, kw_start, kw_stop, kw_drive, kw_sd, kw_subdisk = kw_sd, kw_plex, kw_volume, kw_vol = kw_volume, kw_read, kw_readpol, kw_org, kw_name, kw_concat, kw_striped, kw_raid5, kw_driveoffset, kw_plexoffset, kw_len, kw_length = kw_len, kw_state, kw_setupstate, kw_d, /* flag names */ kw_f, kw_r, kw_s, kw_v, kw_round, /* round robin */ kw_prefer, /* prefer plex */ kw_device, kw_init, kw_label, kw_resetconfig, kw_writethrough, kw_writeback, kw_raw, kw_resetstats, kw_attach, kw_detach, kw_rename, kw_printconfig, kw_replace, kw_detached, #ifdef DEBUG kw_debug, /* go into debugger */ - kw_info, #endif + kw_info, kw_invalid_keyword = -1 }; struct _keywords { char *name; enum keyword keyword; }; struct keywordset { int size; struct _keywords *k; }; extern struct _keywords keywords[]; extern struct _keywords flag_keywords[]; extern struct keywordset keyword_set; extern struct keywordset flag_set; diff --git a/sys/dev/vinum/vinummemory.c b/sys/dev/vinum/vinummemory.c index 5dee671167b0..e77af7e82f5e 100644 --- a/sys/dev/vinum/vinummemory.c +++ b/sys/dev/vinum/vinummemory.c @@ -1,186 +1,198 @@ - /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: memory.c,v 1.16 1998/08/08 04:43:22 grog Exp grog $ + * $Id: memory.c,v 1.17 1998/09/29 05:18:09 grog Exp grog $ */ #define REALLYKERNEL #define USES_VM #include "vinumhdr.h" extern jmp_buf command_fail; /* return on a failed command */ +#ifdef DEBUG +#include "request.h" +extern struct rqinfo rqinfo[]; +extern struct rqinfo *rqip; +#endif + #if __FreeBSD__ >= 3 /* Why aren't these declared anywhere? XXX */ int setjmp(jmp_buf); void longjmp(jmp_buf, int); #endif void freedatabuf(struct mc *me); caddr_t allocdatabuf(struct mc *me); void expand_table(void **table, int oldsize, int newsize) { if (newsize > oldsize) { int *temp; temp = (int *) Malloc(newsize); /* allocate a new table */ CHECKALLOC(temp, "vinum: Can't expand table\n"); if (*table != NULL) { /* already something there, */ bcopy((char *) *table, (char *) temp, oldsize); /* copy it to the old table */ Free(*table); } *table = temp; } } -#ifndef DEBUG -/* increase the size of a request block */ -void -expandrq(struct plexrq *prq) -{ - expand_table((void **) &prq->rqe, - prq->requests * sizeof(struct rqelement), - (prq->requests + RQELTS) * sizeof(struct rqelement)); - bzero(&prq->rqe[prq->requests], RQELTS * sizeof(struct rqelement)); /* clear the new part */ - prq->rqcount += RQELTS; -} - -#endif - #if DEBUG /* XXX debug */ #define MALLOCENTRIES 16384 int malloccount = 0; int highwater = 0; /* highest index ever allocated */ static struct mc malloced[MALLOCENTRIES]; static total_malloced; caddr_t MMalloc(int size, char *file, int line) { caddr_t result; int i; static int seq = 0; int s; struct mc me; /* information to pass to allocdatabuf */ if (malloccount >= MALLOCENTRIES) { /* too many */ printf("vinum: can't allocate table space to trace memory allocation"); return 0; /* can't continue */ } result = malloc(size, M_DEVBUF, M_WAITOK); /* use malloc for smaller and irregular stuff */ if (result == NULL) printf("vinum: can't allocate %d bytes from %s:%d\n", size, file, line); else { me.flags = 0; /* allocation via malloc */ s = splhigh(); for (i = 0; i < malloccount; i++) { if (((result + size) > malloced[i].address) && (result < malloced[i].address + malloced[i].size)) /* overlap */ Debugger("Malloc overlap"); } if (result) { + char *f = index(file, '/'); /* chop off dirname if present */ + + if (f == NULL) + f = file; i = malloccount++; total_malloced += size; malloced[i].address = result; malloced[i].size = size; malloced[i].line = line; malloced[i].seq = seq++; malloced[i].flags = me.flags; malloced[i].databuf = me.databuf; /* only used with kva alloc */ - bcopy(file, malloced[i].file, min(strlen(file) + 1, 16)); + bcopy(f, malloced[i].file, min(strlen(f) + 1, 16)); } if (malloccount > highwater) highwater = malloccount; splx(s); } return result; } void FFree(void *mem, char *file, int line) { int i; int s; s = splhigh(); for (i = 0; i < malloccount; i++) { if ((caddr_t) mem == malloced[i].address) { /* found it */ bzero(mem, malloced[i].size); /* XXX */ free(mem, M_DEVBUF); malloccount--; total_malloced -= malloced[i].size; if (i < malloccount) /* more coming after */ bcopy(&malloced[i + 1], &malloced[i], (malloccount - i) * sizeof(struct mc)); splx(s); return; } } splx(s); printf("Freeing unallocated data at 0x%08x from %s, line %d\n", (int) mem, file, line); Debugger("Free"); } void vinum_meminfo(caddr_t data) { struct meminfo *m = (struct meminfo *) data; m->mallocs = malloccount; m->total_malloced = total_malloced; m->malloced = malloced; m->highwater = highwater; } int vinum_mallocinfo(caddr_t data) { struct mc *m = (struct mc *) data; unsigned int ent = *(int *) data; /* 1st word is index */ if (ent >= malloccount) return ENOENT; m->address = malloced[ent].address; m->size = malloced[ent].size; m->line = malloced[ent].line; m->seq = malloced[ent].seq; bcopy(malloced[ent].file, m->file, 16); return 0; } +/* return the nth request trace buffer entry. This + * is indexed back from the current entry (which + * has index 0) */ +int +vinum_rqinfo(caddr_t data) +{ + struct rqinfo *rq = (struct rqinfo *) data; + int ent = *(int *) data; /* 1st word is index */ + int lastent = rqip - rqinfo; /* entry number of current entry */ + + if (ent >= RQINFO_SIZE) /* out of the table */ + return ENOENT; + if ((ent = lastent - ent - 1) < 0) + ent += RQINFO_SIZE; /* roll over backwards */ + bcopy(&rqinfo[ent], rq, sizeof(struct rqinfo)); + return 0; +} #endif diff --git a/sys/dev/vinum/vinumrequest.c b/sys/dev/vinum/vinumrequest.c index 589eb3fac0ba..94df5b9f06bc 100644 --- a/sys/dev/vinum/vinumrequest.c +++ b/sys/dev/vinum/vinumrequest.c @@ -1,882 +1,947 @@ /* XXX to do: * Decide where we need splbio () */ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * - * $Id: request.c,v 1.17 1998/08/13 06:04:47 grog Exp grog $ + * $Id: request.c,v 1.18 1998/08/31 23:45:35 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" #include #include /* pointer to ioctl p parameter, to save passing it around */ extern struct proc *myproc; enum requeststatus bre(struct request *rq, int plexno, daddr_t * diskstart, daddr_t diskend); enum requeststatus bre5(struct request *rq, int plexno, daddr_t * diskstart, daddr_t diskend); enum requeststatus build_read_request(struct request *rq, int volplexno); enum requeststatus build_write_request(struct request *rq); enum requeststatus build_rq_buffer(struct rqelement *rqe, struct plex *plex); void freerq(struct request *rq); void free_rqg(struct rqgroup *rqg); int find_alternate_sd(struct request *rq); int check_range_covered(struct request *); void complete_rqe(struct buf *bp); void complete_raid5_write(struct rqelement *); int abortrequest(struct request *rq, int error); void sdio(struct buf *bp); void sdio_done(struct buf *bp); int vinum_bounds_check(struct buf *bp, struct volume *vol); caddr_t allocdatabuf(struct rqelement *rqe); void freedatabuf(struct rqelement *rqe); +#ifdef DEBUG +struct rqinfo rqinfo[RQINFO_SIZE]; +struct rqinfo *rqip = rqinfo; + +void +logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp) +{ + BROKEN_GDB; + int s = splhigh(); + + vinum_conf.rqipp = &rqip; /* XXX for broken gdb */ + vinum_conf.rqinfop = rqinfo; /* XXX for broken gdb */ + +#if __FreeBSD__ < 3 + rqip->timestamp = time; /* when did this happen? */ +#else + microtime(&rqip->timestamp); /* when did this happen? */ +#endif + rqip->type = type; + rqip->bp = ubp; /* user buffer */ + switch (type) { + case loginfo_user_bp: + case loginfo_user_bpl: + bcopy(info.bp, &rqip->info.b, sizeof(struct buf)); + break; + + case loginfo_iodone: + case loginfo_rqe: + case loginfo_raid5_data: + case loginfo_raid5_parity: + bcopy(info.rqe, &rqip->info.rqe, sizeof(struct rqelement)); + break; + + case loginfo_unused: + break; + } + rqip++; + if (rqip >= &rqinfo[RQINFO_SIZE]) /* wrap around */ + rqip = rqinfo; + splx(s); +} + +#endif + void vinumstrategy(struct buf *bp) { BROKEN_GDB; int volno; struct volume *vol = NULL; int s; struct devcode *device = (struct devcode *) &bp->b_dev; /* decode device number */ enum requeststatus status; + /* We may have changed the configuration in + * an interrupt context. Update it now. It + * could change again, so do it in a loop. + * XXX this is broken and contains a race condition. + * The correct way is to hand it off the the Vinum + * daemon, but I haven't found a name for it yet */ + while (vinum_conf.flags & VF_DIRTYCONFIG) { /* config is dirty, save it now */ + vinum_conf.flags &= ~VF_DIRTYCONFIG; /* turn it off */ + save_config(); + } + switch (device->type) { case VINUM_SD_TYPE: sdio(bp); return; /* In fact, vinum doesn't handle drives: they're * handled directly by the disk drivers */ case VINUM_DRIVE_TYPE: default: bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; biodone(bp); return; case VINUM_VOLUME_TYPE: /* volume I/O */ volno = VOLNO(bp->b_dev); vol = &VOL[volno]; if (vol->state != volume_up) { /* can't access this volume */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; biodone(bp); return; } if (vinum_bounds_check(bp, vol) <= 0) { /* don't like them bounds */ biodone(bp); /* have nothing to do with this */ return; } /* FALLTHROUGH */ /* Plex I/O is pretty much the same as volume I/O * for a single plex. Indicate this by passing a NULL * pointer (set above) for the volume */ case VINUM_PLEX_TYPE: bp->b_resid = bp->b_bcount; /* transfer everything */ vinumstart(bp, 0); return; } } /* Start a transfer. Return -1 on error, * 0 if OK, 1 if we need to retry. * Parameter reviveok is set when doing * transfers for revives: it allows transfers to * be started immediately when a revive is in * progress. During revive, normal transfers * are queued if they share address space with * a currently active revive operation. */ int vinumstart(struct buf *bp, int reviveok) { BROKEN_GDB; int plexno; int maxplex; /* maximum number of plexes to handle */ struct volume *vol; struct rqgroup *rqg; /* current plex's requests */ struct rqelement *rqe; /* individual element */ struct request *rq; /* build up our request here */ int rqno; /* index in request list */ enum requeststatus status; +#if DEBUG + if (debug & DEBUG_LASTREQS) + logrq(loginfo_user_bp, bp, bp); +#endif + /* XXX In these routines, we're assuming that * we will always be called with bp->b_bcount * which is a multiple of the sector size. This * is a reasonable assumption, since we are only * called from system routines. Should we check * anyway? */ if ((bp->b_bcount % DEV_BSIZE) != 0) { /* bad length */ bp->b_error = EINVAL; /* invalid size */ bp->b_flags |= B_ERROR; biodone(bp); return -1; } rq = (struct request *) Malloc(sizeof(struct request)); /* allocate a request struct */ if (rq == NULL) { /* can't do it */ bp->b_error = ENOMEM; /* can't get memory */ bp->b_flags |= B_ERROR; biodone(bp); return -1; } bzero(rq, sizeof(struct request)); /* Note the volume ID. This can be NULL, which * the request building functions use as an * indication for single plex I/O */ rq->bp = bp; /* and the user buffer struct */ if (DEVTYPE(bp->b_dev) == VINUM_VOLUME_TYPE) { /* it's a volume, */ rq->volplex.volno = VOLNO(bp->b_dev); /* get the volume number */ vol = &VOL[rq->volplex.volno]; /* and point to it */ vol->active++; /* one more active request */ maxplex = vol->plexes; /* consider all its plexes */ } else { vol = NULL; /* no volume */ rq->volplex.plexno = PLEXNO(bp->b_dev); /* point to the plex */ rq->isplex = 1; /* note that it's a plex */ maxplex = 1; /* just the one plex */ } if (bp->b_flags & B_READ) { /* This is a read request. Decide * which plex to read from. * * There's a potential race condition here, * since we're not locked, and we could end * up multiply incrementing the round-robin * counter. This doesn't have any serious * effects, however. */ if (vol != NULL) { vol->reads++; vol->bytes_read += bp->b_bcount; plexno = vol->preferred_plex; /* get the plex to use */ if (plexno < 0) { /* round robin */ plexno = vol->last_plex_read; vol->last_plex_read++; if (vol->last_plex_read == vol->plexes) /* got the the end? */ vol->last_plex_read = 0; /* wrap around */ } status = build_read_request(rq, plexno); /* build a request */ } else { daddr_t diskaddr = bp->b_blkno; /* start offset of transfer */ status = bre(rq, /* build a request list */ rq->volplex.plexno, &diskaddr, diskaddr + (bp->b_bcount / DEV_BSIZE)); } if ((status > REQUEST_RECOVERED) /* can't satisfy it */ ||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */ if (status == REQUEST_DOWN) { /* not enough subdisks */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; } biodone(bp); freerq(rq); return -1; - } - return launch_requests(rq, reviveok); /* now start the requests if we can */ + } + return launch_requests(rq, reviveok); /* now start the requests if we can */ } else /* This is a write operation. We write to all * plexes. If this is a RAID 5 plex, we must also * update the parity stripe. */ { if (vol != NULL) { vol->writes++; vol->bytes_written += bp->b_bcount; status = build_write_request(rq); /* Not all the subdisks are up */ } else { /* plex I/O */ daddr_t diskstart; diskstart = bp->b_blkno; /* start offset of transfer */ status = bre(rq, PLEXNO(bp->b_dev), &diskstart, bp->b_blkno + (bp->b_bcount / DEV_BSIZE)); /* build requests for the plex */ } if ((status > REQUEST_RECOVERED) /* can't satisfy it */ ||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */ if (status == REQUEST_DOWN) { /* not enough subdisks */ bp->b_error = EIO; /* I/O error */ bp->b_flags |= B_ERROR; } if ((bp->b_flags & B_DONE) == 0) biodone(bp); freerq(rq); return -1; - } - return launch_requests(rq, reviveok); /* start the requests */ + } + return launch_requests (rq, reviveok); /* start the requests */ } } /* Call the low-level strategy routines to * perform the requests in a struct request */ int launch_requests(struct request *rq, int reviveok) { struct rqgroup *rqg; int rqno; /* loop index */ struct rqelement *rqe; /* current element */ int s; /* First find out whether we're reviving, and the * request contains a conflict. If so, we hang * the request off plex->waitlist of the first * plex we find which is reviving */ if ((rq->flags & XFR_REVIVECONFLICT) /* possible revive conflict */ &&(!reviveok)) { /* and we don't want to do it now, */ struct volume *vol = &VOL[VOLNO(rq->bp->b_dev)]; struct plex *plex; int plexno; for (plexno = 0; plexno < vol->plexes; plexno++) { /* find the reviving plex */ plex = &PLEX[vol->plex[plexno]]; if (plex->state == plex_reviving) /* found it */ break; } if (plexno < vol->plexes) { /* found it? */ struct request *waitlist = plex->waitlist; /* point to the waiting list */ while (waitlist->next != NULL) /* find the end */ waitlist = waitlist->next; waitlist->next = rq; /* hook our request there */ return 0; /* and get out of here */ } else /* bad vinum, bad */ printf("vinum: can't find reviving plex for volume %s\n", vol->name); } rq->active = 0; /* nothing yet */ /* XXX This is probably due to a bug */ if (rq->rqg == NULL) { /* no request */ abortrequest(rq, EINVAL); return -1; } #if DEBUG if (debug & DEBUG_ADDRESSES) - printf("Request: %x\nWrite dev 0x%x, offset 0x%x, length %ld\n", + printf("Request: %x\n%s dev 0x%x, offset 0x%x, length %ld\n", (u_int) rq, + rq->bp->b_flags & B_READ ? "Read" : "Write", rq->bp->b_dev, rq->bp->b_blkno, rq->bp->b_bcount); /* XXX */ vinum_conf.lastrq = (int) rq; vinum_conf.lastbuf = rq->bp; + if (debug & DEBUG_LASTREQS) + logrq(loginfo_user_bpl, rq->bp, rq->bp); #endif for (rqg = rq->rqg; rqg != NULL; rqg = rqg->next) { /* through the whole request chain */ rqg->active = rqg->count; /* they're all active */ rq->active++; /* one more active request group */ for (rqno = 0; rqno < rqg->count; rqno++) { rqe = &rqg->rqe[rqno]; if (rqe->flags & XFR_BAD_SUBDISK) /* this subdisk is bad, */ rqg->active--; /* one less active request */ else { struct drive *drive = &DRIVE[rqe->driveno]; /* drive to access */ if ((rqe->b.b_flags & B_READ) == 0) rqe->b.b_vp->v_numoutput++; /* one more output going */ #if DEBUG if (debug & DEBUG_ADDRESSES) printf(" %s dev 0x%x, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n", rqe->b.b_flags & B_READ ? "Read" : "Write", rqe->b.b_dev, rqe->sdno, (u_int) (rqe->b.b_blkno - SD[rqe->sdno].driveoffset), rqe->b.b_blkno, rqe->b.b_bcount); /* XXX */ if (debug & DEBUG_NUMOUTPUT) printf(" vinumstart sd %d numoutput %ld\n", rqe->sdno, rqe->b.b_vp->v_numoutput); + if (debug & DEBUG_LASTREQS) + logrq(loginfo_rqe, rqe, rq->bp); #endif /* fire off the request */ s = splbio(); (*bdevsw[major(rqe->b.b_dev)]->d_strategy) (&rqe->b); splx(s); } /* XXX Do we need caching? Think about this more */ } } return 0; } /* define the low-level requests needed to perform a * high-level I/O operation for a specific plex 'plexno'. * * Return 0 if all subdisks involved in the request are up, 1 if some * subdisks are not up, and -1 if the request is at least partially * outside the bounds of the subdisks. * * Modify the pointer *diskstart to point to the end address. On * read, return on the first bad subdisk, so that the caller * (build_read_request) can try alternatives. * * On entry to this routine, the rqg structures are not assigned. The * assignment is performed by expandrq(). Strictly speaking, the * elements rqe->sdno of all entries should be set to -1, since 0 * (from bzero) is a valid subdisk number. We avoid this problem by * initializing the ones we use, and not looking at the others (index * >= rqg->requests). */ enum requeststatus bre(struct request *rq, int plexno, daddr_t * diskaddr, daddr_t diskend) { BROKEN_GDB; int sdno; struct sd *sd; struct rqgroup *rqg; struct buf *bp; /* user's bp */ struct plex *plex; enum requeststatus status; /* return value */ daddr_t plexoffset; /* offset of transfer in plex */ daddr_t stripebase; /* base address of stripe (1st subdisk) */ daddr_t stripeoffset; /* offset in stripe */ daddr_t blockoffset; /* offset in stripe on subdisk */ struct rqelement *rqe; /* point to this request information */ daddr_t diskstart = *diskaddr; /* remember where this transfer starts */ bp = rq->bp; /* buffer pointer */ status = REQUEST_OK; /* return value: OK until proven otherwise */ plex = &PLEX[plexno]; /* point to the plex */ switch (plex->organization) { case plex_concat: for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; if ((*diskaddr < (sd->plexoffset + sd->sectors)) /* The request starts before the end of this */ &&(diskend > sd->plexoffset)) { /* subdisk and ends after the start of this sd */ if ((sd->state != sd_up) || (plex->state != plex_up)) { enum requeststatus s; s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */ if (s) /* give up? */ return s; /* yup */ } rqg = allocrqg(rq, 1); /* space for the request */ if (rqg == NULL) { /* malloc failed */ bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; } rqg->plexno = plexno; rqe = &rqg->rqe[0]; /* point to the element */ rqe->rqg = rqg; /* group */ rqe->sdno = sd->sdno; /* put in the subdisk number */ plexoffset = max(sd->plexoffset, *diskaddr); /* start offset in plex */ rqe->sdoffset = plexoffset - sd->plexoffset; /* start offset in subdisk */ rqe->useroffset = plexoffset - diskstart; /* start offset in user buffer */ rqe->dataoffset = 0; rqe->datalen = min(diskend - *diskaddr, /* number of sectors to transfer in this sd */ sd->sectors - rqe->sdoffset); rqe->groupoffset = 0; /* no groups for concatenated plexes */ rqe->grouplen = 0; rqe->buflen = rqe->datalen; /* buffer length is data buffer length */ rqe->flags = 0; rqe->driveno = sd->driveno; *diskaddr += rqe->datalen; /* bump the address */ if (build_rq_buffer(rqe, plex)) { /* build the buffer */ deallocrqg(rqg); bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; /* can't do it */ } } if (*diskaddr > diskend) /* we're finished, */ break; /* get out of here */ } break; case plex_striped: { while (*diskaddr < diskend) { /* until we get it all sorted out */ /* The offset of the start address from * the start of the stripe */ stripeoffset = *diskaddr % (plex->stripesize * plex->subdisks); /* The plex-relative address of the * start of the stripe */ stripebase = *diskaddr - stripeoffset; /* The number of the subdisk in which * the start is located */ sdno = stripeoffset / plex->stripesize; /* The offset from the beginning of the stripe * on this subdisk */ blockoffset = stripeoffset % plex->stripesize; sd = &SD[plex->sdnos[sdno]]; /* the subdisk in question */ if ((sd->state != sd_up) || (plex->state != plex_up)) { enum requeststatus s; s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */ if (s) /* give up? */ return s; /* yup */ } rqg = allocrqg(rq, 1); /* space for the request */ if (rqg == NULL) { /* malloc failed */ bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; } rqg->plexno = plexno; rqe = &rqg->rqe[0]; /* point to the element */ rqe->rqg = rqg; rqe->sdoffset = stripebase / plex->subdisks + blockoffset; /* start offset in this subdisk */ rqe->useroffset = *diskaddr - diskstart; /* The offset of the start in the user buffer */ rqe->dataoffset = 0; rqe->datalen = min(diskend - *diskaddr, /* the amount remaining to transfer */ plex->stripesize - blockoffset); /* and the amount left in this stripe */ rqe->groupoffset = 0; /* no groups for striped plexes */ rqe->grouplen = 0; rqe->buflen = rqe->datalen; /* buffer length is data buffer length */ rqe->flags = 0; rqe->sdno = sd->sdno; /* put in the subdisk number */ rqe->driveno = sd->driveno; if (rqe->sdoffset >= sd->sectors) { /* starts beyond the end of the subdisk? */ deallocrqg(rqg); return REQUEST_EOF; } else if (rqe->sdoffset + rqe->datalen > sd->sectors) /* ends beyond the end of the subdisk? */ rqe->datalen = sd->sectors - rqe->sdoffset; /* yes, truncate */ if (build_rq_buffer(rqe, plex)) { /* build the buffer */ deallocrqg(rqg); bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return REQUEST_ENOMEM; /* can't do it */ } *diskaddr += rqe->datalen; /* look at the remainder */ if (*diskaddr < diskend) { /* didn't finish the request on this stripe */ plex->multiblock++; /* count another one */ if (sdno == plex->subdisks - 1) /* last subdisk, */ plex->multistripe++; /* another stripe as well */ } } } break; default: printf("vinum: invalid plex type in bre"); } return status; } /* Build up a request structure for reading volumes. * This function is not needed for plex reads, since there's * no recovery if a plex read can't be satisified. */ enum requeststatus build_read_request(struct request *rq, /* request */ int plexindex) { /* index in the volume's plex table */ BROKEN_GDB; struct buf *bp; daddr_t startaddr; /* offset of previous part of transfer */ daddr_t diskaddr; /* offset of current part of transfer */ daddr_t diskend; /* and end offset of transfer */ int plexno; /* plex index in vinum_conf */ struct rqgroup *rqg; /* point to the request we're working on */ struct volume *vol; /* volume in question */ off_t oldstart; /* note where we started */ int recovered = 0; /* set if we recover a read */ enum requeststatus status = REQUEST_OK; bp = rq->bp; /* buffer pointer */ diskaddr = bp->b_blkno; /* start offset of transfer */ diskend = diskaddr + (bp->b_bcount / DEV_BSIZE); /* and end offset of transfer */ rqg = &rq->rqg[plexindex]; /* plex request */ vol = &VOL[rq->volplex.volno]; /* point to volume */ while (diskaddr < diskend) { /* build up request components */ startaddr = diskaddr; status = bre(rq, vol->plex[plexindex], &diskaddr, diskend); /* build up a request */ switch (status) { case REQUEST_OK: continue; case REQUEST_RECOVERED: recovered = 1; break; case REQUEST_EOF: case REQUEST_ENOMEM: return status; /* if we get here, we have either had a failure or * a RAID 5 recovery. We don't want to use the * recovery, because it's expensive, so first we * check if we have alternatives */ case REQUEST_DOWN: /* can't access the plex */ if (vol != NULL) { /* and this is volume I/O */ /* Try to satisfy the request * from another plex */ for (plexno = 0; plexno < vol->plexes; plexno++) { diskaddr = startaddr; /* start at the beginning again */ oldstart = startaddr; /* and note where that was */ if (plexno != plexindex) { /* don't try this plex again */ bre(rq, vol->plex[plexno], &diskaddr, diskend); /* try a request */ if (diskaddr > oldstart) { /* we satisfied another part */ recovered = 1; /* we recovered from the problem */ status = REQUEST_OK; /* don't complain about it */ break; } } if (plexno == (vol->plexes - 1)) /* couldn't satisfy the request */ return REQUEST_DOWN; /* failed */ } } else return REQUEST_DOWN; /* bad luck */ } if (recovered) vol->recovered_reads += recovered; /* adjust our recovery count */ } return status; } /* Build up a request structure for writes. * Return 0 if all subdisks involved in the request are up, 1 if some * subdisks are not up, and -1 if the request is at least partially * outside the bounds of the subdisks. */ enum requeststatus build_write_request(struct request *rq) { /* request */ BROKEN_GDB; struct buf *bp; daddr_t diskstart; /* offset of current part of transfer */ daddr_t diskend; /* and end offset of transfer */ int plexno; /* plex index in vinum_conf */ struct volume *vol; /* volume in question */ enum requeststatus status; bp = rq->bp; /* buffer pointer */ vol = &VOL[rq->volplex.volno]; /* point to volume */ diskend = bp->b_blkno + (bp->b_bcount / DEV_BSIZE); /* end offset of transfer */ status = REQUEST_OK; for (plexno = 0; plexno < vol->plexes; plexno++) { diskstart = bp->b_blkno; /* start offset of transfer */ status = min(status, bre(rq, /* build requests for the plex */ vol->plex[plexno], &diskstart, diskend)); } return status; } /* Fill in the struct buf part of a request element. */ enum requeststatus build_rq_buffer(struct rqelement *rqe, struct plex *plex) { BROKEN_GDB; struct sd *sd; /* point to subdisk */ struct volume *vol; struct buf *bp; struct buf *ubp; /* user (high level) buffer header */ vol = &VOL[rqe->rqg->rq->volplex.volno]; sd = &SD[rqe->sdno]; /* point to subdisk */ bp = &rqe->b; ubp = rqe->rqg->rq->bp; /* pointer to user buffer header */ /* Initialize the buf struct */ bzero(&rqe->b, sizeof(struct buf)); bp->b_proc = ubp->b_proc; /* process pointer */ bp->b_flags = ubp->b_flags & (B_NOCACHE | B_READ | B_ASYNC); /* copy these flags from user bp */ bp->b_flags |= B_CALL | B_BUSY; /* inform us when it's done */ if (plex->state == plex_reviving) bp->b_flags |= B_ORDERED; /* keep request order if we're reviving */ bp->b_iodone = complete_rqe; /* by calling us here */ bp->b_dev = DRIVE[rqe->driveno].dev; /* drive device */ bp->b_blkno = rqe->sdoffset + sd->driveoffset; /* start address */ bp->b_bcount = rqe->buflen << DEV_BSHIFT; /* number of bytes to transfer */ bp->b_resid = bp->b_bcount; /* and it's still all waiting */ bp->b_bufsize = bp->b_bcount; /* and buffer size */ bp->b_vp = DRIVE[rqe->driveno].vp; /* drive vnode */ bp->b_rcred = FSCRED; /* we have the file system credentials */ bp->b_wcred = FSCRED; /* we have the file system credentials */ if (rqe->flags & XFR_MALLOCED) { /* this operation requires a malloced buffer */ bp->b_data = Malloc(bp->b_bcount); /* get a buffer to put it in */ if (bp->b_data == NULL) { /* failed */ Debugger("XXX"); abortrequest(rqe->rqg->rq, ENOMEM); return REQUEST_ENOMEM; /* no memory */ } } else /* Point directly to user buffer data. This means * that we don't need to do anything when we have * finished the transfer */ bp->b_data = ubp->b_data + rqe->useroffset * DEV_BSIZE; return 0; } /* Abort a request: free resources and complete the * user request with the specified error */ int abortrequest(struct request *rq, int error) { struct buf *bp = rq->bp; /* user buffer */ bp->b_flags |= B_ERROR; bp->b_error = error; freerq(rq); /* free everything we're doing */ biodone(bp); return error; /* and give up */ } /* Check that our transfer will cover the * complete address space of the user request. * * Return 1 if it can, otherwise 0 */ int check_range_covered(struct request *rq) { /* XXX */ return 1; } /* Perform I/O on a subdisk */ void sdio(struct buf *bp) { int s; /* spl */ struct sd *sd; struct sdbuf *sbp; daddr_t endoffset; struct drive *drive; sd = &SD[SDNO(bp->b_dev)]; /* point to the subdisk */ drive = &DRIVE[sd->driveno]; if (drive->state != drive_up) { /* XXX until we get the states fixed */ set_sd_state(SDNO(bp->b_dev), sd_obsolete, setstate_force); bp->b_flags |= B_ERROR; bp->b_error = EIO; biodone(bp); return; } /* XXX decide which states we will really accept here. up * implies it could be involved with a plex, in which * case we don't want to dick with it */ if ((sd->state != sd_up) && (sd->state != sd_initializing) && (sd->state != sd_reborn)) { /* we can't access it */ bp->b_flags |= B_ERROR; bp->b_flags = EIO; if (bp->b_flags & B_BUSY) /* XXX why isn't this always the case? */ biodone(bp); return; } /* Get a buffer */ sbp = (struct sdbuf *) Malloc(sizeof(struct sdbuf)); if (sbp == NULL) { bp->b_flags |= B_ERROR; bp->b_error = ENOMEM; biodone(bp); return; } bcopy(bp, &sbp->b, sizeof(struct buf)); /* start with the user's buffer */ sbp->b.b_flags |= B_CALL; /* tell us when it's done */ sbp->b.b_iodone = sdio_done; /* here */ sbp->b.b_dev = DRIVE[sd->driveno].dev; /* device */ sbp->b.b_vp = DRIVE[sd->driveno].vp; /* vnode */ sbp->b.b_blkno += sd->driveoffset; sbp->bp = bp; /* note the address of the original header */ sbp->sdno = sd->sdno; /* note for statistics */ sbp->driveno = sd->driveno; endoffset = bp->b_blkno + sbp->b.b_bcount / DEV_BSIZE; /* final sector offset */ if (endoffset > sd->sectors) { /* beyond the end */ sbp->b.b_bcount -= (endoffset - sd->sectors) * DEV_BSIZE; /* trim */ if (sbp->b.b_bcount <= 0) { /* nothing to transfer */ bp->b_resid = bp->b_bcount; /* nothing transferred */ /* XXX Grrr. This doesn't seem to work. Return * an error after all */ bp->b_flags |= B_ERROR; bp->b_error = ENOSPC; biodone(bp); Free(sbp); return; } } if ((sbp->b.b_flags & B_READ) == 0) /* write */ sbp->b.b_vp->v_numoutput++; /* one more output going */ #if DEBUG if (debug & DEBUG_ADDRESSES) printf(" %s dev 0x%x, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n", sbp->b.b_flags & B_READ ? "Read" : "Write", sbp->b.b_dev, sbp->sdno, (u_int) (sbp->b.b_blkno - SD[sbp->sdno].driveoffset), (int) sbp->b.b_blkno, sbp->b.b_bcount); /* XXX */ if (debug & DEBUG_NUMOUTPUT) printf(" vinumstart sd %d numoutput %ld\n", sbp->sdno, sbp->b.b_vp->v_numoutput); #endif s = splbio(); (*bdevsw[major(sbp->b.b_dev)]->d_strategy) (&sbp->b); splx(s); } /* Simplified version of bounds_check_with_label * Determine the size of the transfer, and make sure it is * within the boundaries of the partition. Adjust transfer * if needed, and signal errors or early completion. * * Volumes are simpler than disk slices: they only contain * one component (though we call them a, b and c to make * system utilities happy), and they always take up the * complete space of the "partition". * * I'm still not happy with this: why should the label be * protected? If it weren't so damned difficult to write * one in the first pleace (because it's protected), it wouldn't * be a problem. */ int vinum_bounds_check(struct buf *bp, struct volume *vol) { int maxsize = vol->size; /* size of the partition (sectors) */ int size = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; /* size of this request (sectors) */ /* Would this transfer overwrite the disk label? */ if (bp->b_blkno <= LABELSECTOR /* starts before or at the label */ #if LABELSECTOR != 0 && bp->b_blkno + size > LABELSECTOR /* and finishes after */ #endif && (!(vol->flags & VF_RAW)) /* and it's not raw */ &&major(bp->b_dev) == BDEV_MAJOR /* and it's the block device */ && (bp->b_flags & B_READ) == 0 /* and it's a write */ && (!vol->flags & (VF_WLABEL | VF_LABELLING))) { /* and we're not allowed to write the label */ bp->b_error = EROFS; /* read-only */ bp->b_flags |= B_ERROR; return -1; } if (size == 0) /* no transfer specified, */ return 0; /* treat as EOF */ /* beyond partition? */ if (bp->b_blkno < 0 /* negative start */ || bp->b_blkno + size > maxsize) { /* or goes beyond the end of the partition */ /* if exactly at end of disk, return an EOF */ if (bp->b_blkno == maxsize) { bp->b_resid = bp->b_bcount; return 0; } /* or truncate if part of it fits */ size = maxsize - bp->b_blkno; if (size <= 0) { /* nothing to transfer */ bp->b_error = EINVAL; bp->b_flags |= B_ERROR; return -1; } bp->b_bcount = size << DEV_BSHIFT; } bp->b_pblkno = bp->b_blkno; return 1; } /* Allocate a request group and hook * it in in the list for rq */ struct rqgroup * allocrqg(struct request *rq, int elements) { struct rqgroup *rqg; /* the one we're going to allocate */ int size = sizeof(struct rqgroup) + elements * sizeof(struct rqelement); rqg = (struct rqgroup *) Malloc(size); if (rqg != NULL) { /* malloc OK, */ if (rq->rqg) /* we already have requests */ rq->lrqg->next = rqg; /* hang it off the end */ else /* first request */ rq->rqg = rqg; /* at the start */ rq->lrqg = rqg; /* this one is the last in the list */ bzero(rqg, size); /* no old junk */ rqg->rq = rq; /* point back to the parent request */ rqg->count = elements; /* number of requests in the group */ } else Debugger("XXX"); return rqg; } /* Deallocate a request group out of a chain. We do * this by linear search: the chain is short, this * almost never happens, and currently it can only * happen to the first member of the chain. */ void deallocrqg(struct rqgroup *rqg) { struct rqgroup *rqgc = rqg->rq->rqg; /* point to the request chain */ if (rqg->rq->rqg == rqg) /* we're first in line */ rqg->rq->rqg = rqg->next; /* unhook ourselves */ else { while (rqgc->next != rqg) /* find the group */ rqgc = rqgc->next; rqgc->next = rqg->next; } Free(rqgc); } /* Character device interface */ int vinumread(dev_t dev, struct uio *uio, int ioflag) { return (physio(vinumstrategy, NULL, dev, 1, minphys, uio)); } int vinumwrite(dev_t dev, struct uio *uio, int ioflag) { return (physio(vinumstrategy, NULL, dev, 0, minphys, uio)); } diff --git a/sys/dev/vinum/vinumstate.c b/sys/dev/vinum/vinumstate.c index 2ce2ed0c29e5..928cb38765b1 100644 --- a/sys/dev/vinum/vinumstate.c +++ b/sys/dev/vinum/vinumstate.c @@ -1,755 +1,759 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: state.c,v 2.6 1998/08/19 08:04:47 grog Exp grog $ */ #define REALLYKERNEL #include "vinumhdr.h" #include "request.h" /* Update drive state */ /* Return 1 if the state changes, otherwise 0 */ int set_drive_state(int driveno, enum drivestate state, int flags) { struct drive *drive = &DRIVE[driveno]; int oldstate = drive->state; int sdno; if (drive->state == drive_unallocated) /* no drive to do anything with, */ return 0; if (state != oldstate) { /* don't change it if it's not different */ if (state == drive_down) { /* the drive's going down */ if (flags || (drive->opencount == 0)) { /* we can do it */ close_drive(drive); drive->state = state; printf("vinum: drive %s is %s\n", drive->label.name, drive_state(drive->state)); } else return 0; /* don't do it */ } drive->state = state; /* set the state */ if (((drive->state == drive_up) || ((drive->state == drive_coming_up))) && (drive->vp == NULL)) /* should be open, but we're not */ init_drive(drive); /* which changes the state again */ if ((state != oldstate) /* state has changed */ &&((flags & setstate_norecurse) == 0)) { /* and we want to recurse, */ for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { /* find this drive's subdisks */ if (SD[sdno].driveno == driveno) /* belongs to this drive */ set_sd_state(sdno, sd_down, setstate_force | setstate_recursing); /* take it down */ } save_config(); /* and save the updated configuration */ return 1; } } return 0; } /* Try to set the subdisk state. Return 1 if state changed to * what we wanted, -1 if it changed to something else, and 0 * if no change. * * This routine is called both from the user (up, down states * only) and internally. */ int set_sd_state(int sdno, enum sdstate state, enum setstateflags flags) { struct sd *sd = &SD[sdno]; int oldstate = sd->state; int status = 1; /* status to return */ if (state == oldstate) return 0; /* no change */ if (sd->state == sd_unallocated) /* no subdisk to do anything with, */ return 0; if (sd->driveoffset < 0) { /* not allocated space */ sd->state = sd_down; if (state != sd_down) return -1; } else { /* space allocated */ switch (state) { case sd_down: if ((!flags & setstate_force) /* but gently */ &&(sd->plexno >= 0)) /* and we're attached to a plex, */ return 0; /* don't do it */ break; case sd_up: if (DRIVE[sd->driveno].state != drive_up) /* can't bring the sd up if the drive isn't, */ return 0; /* not even by force */ switch (sd->state) { case sd_obsolete: case sd_down: /* been down, no data lost */ if ((sd->plexno) /* we're associated with a plex */ &&(((PLEX[sd->plexno].state < plex_firstup) /* and it's not up */ ||(PLEX[sd->plexno].subdisks > 1)))) /* or it's the only one */ break; /* XXX Get this right: make sure that other plexes in * the volume cover this address space, otherwise * we make this one sd_up */ sd->state = sd_reborn; /* here it is again */ printf("vinum: subdisk %s is %s, not %s\n", sd->name, sd_state(sd->state), sd_state(state)); status = -1; break; case sd_init: /* brand new */ if (flags & setstate_configuring) /* we're doing this while configuring */ break; sd->state = sd_empty; /* nothing in it */ printf("vinum: subdisk %s is %s, not %s\n", sd->name, sd_state(sd->state), sd_state(state)); status = -1; break; case sd_initializing: break; /* go on and do it */ case sd_empty: if ((sd->plexno) /* we're associated with a plex */ &&(((PLEX[sd->plexno].state < plex_firstup) /* and it's not up */ ||(PLEX[sd->plexno].subdisks > 1)))) /* or it's the only one */ break; return 0; /* can't do it */ default: /* can't do it */ /* There's no way to bring subdisks up directly from * other states. First they need to be initialized * or revived */ return 0; } break; default: /* other ones, only internal with force */ if (flags & setstate_force == 0) /* no force? What's this? */ return 0; /* don't do it */ } } sd->state = state; printf("vinum: subdisk %s is %s\n", sd->name, sd_state(sd->state)); if ((flags & setstate_norecurse) == 0) set_plex_state(sd->plexno, plex_up, setstate_recursing); /* update plex state */ - if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ - save_config(); + if ((flags & (setstate_configuring | setstate_recursing)) == 0) { /* save config now */ + if (setstate_noupdate) /* we can't update now, */ + vinum_conf.flags |= VF_DIRTYCONFIG; /* wait until later */ + else + save_config(); + } return status; } /* Called from request routines when they find * a subdisk which is not kosher. Decide whether * it warrants changing the state. Return * REQUEST_DOWN if we can't use the subdisk, * REQUEST_OK if we can. */ enum requeststatus checksdstate(struct sd *sd, struct request *rq, daddr_t diskaddr, daddr_t diskend) { struct plex *plex = &PLEX[sd->plexno]; int writeop = (rq->bp->b_flags & B_READ) == 0; /* note if we're writing */ /* first, see if the plex wants to be accessed */ switch (plex->state) { case plex_reviving: /* When writing, we'll write anything that starts * up to the current revive pointer, but we'll * only accept a read which finishes before the * current revive pointer. */ if ((writeop && (diskaddr > plex->revived)) /* write starts after current revive pointer */ ||((!writeop) && (diskend >= plex->revived))) { /* or read ends after current revive pointer */ if (writeop) { /* writing to a consistent down disk */ if (DRIVE[sd->driveno].state == drive_up) set_sd_state(sd->sdno, sd_stale, setstate_force); /* it's not consistent now */ else set_sd_state(sd->sdno, sd_obsolete, setstate_force); /* it's not consistent now */ } return REQUEST_DOWN; /* that part of the plex is still down */ } else if (diskend >= plex->revived) /* write finishes beyond revive pointer */ rq->flags |= XFR_REVIVECONFLICT; /* note a potential conflict */ /* FALLTHROUGH */ case plex_up: case plex_degraded: case plex_flaky: /* We can access the plex: let's see * how the subdisk feels */ switch (sd->state) { case sd_up: return REQUEST_OK; case sd_reborn: if (writeop) return REQUEST_OK; /* always write to a reborn disk */ /* Handle the mapping. We don't want to reject * a read request to a reborn subdisk if that's * all we have. XXX */ return REQUEST_DOWN; case sd_down: case sd_crashed: if (writeop) { /* writing to a consistent down disk */ if (DRIVE[sd->driveno].state == drive_up) set_sd_state(sd->sdno, sd_stale, setstate_force); /* it's not consistent now */ else set_sd_state(sd->sdno, sd_obsolete, setstate_force); /* it's not consistent now */ } return REQUEST_DOWN; /* and it's down one way or another */ default: return REQUEST_DOWN; } default: return REQUEST_DOWN; } } void add_defective_region(struct plex *plex, off_t offset, size_t length) { /* XXX get this ordered, and coalesce regions if necessary */ if (++plex->defective_regions > plex->defective_region_count) EXPAND(plex->defective_region, struct plexregion, plex->defective_region_count, PLEX_REGION_TABLE_SIZE); plex->defective_region[plex->defective_regions - 1].offset = offset; plex->defective_region[plex->defective_regions - 1].length = length; } void add_unmapped_region(struct plex *plex, off_t offset, size_t length) { if (++plex->unmapped_regions > plex->unmapped_region_count) EXPAND(plex->unmapped_region, struct plexregion, plex->unmapped_region_count, PLEX_REGION_TABLE_SIZE); plex->unmapped_region[plex->unmapped_regions - 1].offset = offset; plex->unmapped_region[plex->unmapped_regions - 1].length = length; } /* Rebuild a plex free list and set state if * we have a configuration error */ void rebuild_plex_unmappedlist(struct plex *plex) { int sdno; struct sd *sd; int lastsdend = 0; /* end offset of last subdisk */ if (plex->unmapped_region != NULL) { /* we're going to rebuild it */ Free(plex->unmapped_region); plex->unmapped_region = NULL; plex->unmapped_regions = 0; plex->unmapped_region_count = 0; } if (plex->defective_region != NULL) { Free(plex->defective_region); plex->defective_region = NULL; plex->defective_regions = 0; plex->defective_region_count = 0; } for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; if (sd->plexoffset < lastsdend) { /* overlap */ printf("vinum: Plex %s, subdisk %s overlaps previous\n", plex->name, sd->name); set_plex_state(plex->plexno, plex_down, setstate_force); /* don't allow that */ } else if (sd->plexoffset > lastsdend) /* gap */ add_unmapped_region(plex, lastsdend, sd->plexoffset - lastsdend); else if (sd->state < sd_reborn) /* this part defective */ add_defective_region(plex, sd->plexoffset, sd->sectors); lastsdend = sd->plexoffset + sd->sectors; } } /* return a state map for the subdisks of a plex */ enum sdstates sdstatemap(struct plex *plex, int *sddowncount) { int sdno; enum sdstates statemap = 0; /* note the states we find */ *sddowncount = 0; /* no subdisks down yet */ for (sdno = 0; sdno < plex->subdisks; sdno++) { struct sd *sd = &SD[plex->sdnos[sdno]]; /* point to the subdisk */ switch (sd->state) { case sd_empty: statemap |= sd_emptystate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_init: statemap |= sd_initstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_down: statemap |= sd_downstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_crashed: statemap |= sd_crashedstate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_obsolete: statemap |= sd_obsolete; (*sddowncount)++; /* another unusable subdisk */ break; case sd_stale: statemap |= sd_stalestate; (*sddowncount)++; /* another unusable subdisk */ break; case sd_reborn: statemap |= sd_rebornstate; break; case sd_up: statemap |= sd_upstate; break; default: statemap |= sd_otherstate; break; } } return statemap; } /* determine the state of the volume relative to this plex */ enum volplexstate vpstate(struct plex *plex) { struct volume *vol; enum volplexstate state = volplex_onlyusdown; /* state to return */ int plexno; if (plex->volno < 0) /* not associated with a volume */ return volplex_onlyusdown; /* assume the worst */ vol = &VOL[plex->volno]; /* point to our volume */ for (plexno = 0; plexno < vol->plexes; plexno++) { if (&PLEX[vol->plex[plexno]] == plex) { /* us */ if (PLEX[vol->plex[plexno]].state == plex_up) /* are we up? */ state |= volplex_onlyus; /* yes */ } else { if (PLEX[vol->plex[plexno]].state == plex_up) /* not us */ state |= volplex_otherup; /* and when they were up, they were up */ else state |= volplex_alldown; /* and when they were down, they were down */ } } return state; /* and when they were only halfway up */ } /* they were neither up nor down */ /* Check if all bits b are set in a */ int allset(int a, int b); int allset(int a, int b) { return (a & b) == b; } /* Update the state of a plex dependent on its subdisks. * Also rebuild the unmapped_region and defective_region table */ int set_plex_state(int plexno, enum plexstate state, enum setstateflags flags) { int sddowncount = 0; /* number of down subdisks */ struct plex *plex = &PLEX[plexno]; /* point to our plex */ enum plexstate oldstate = plex->state; enum volplexstate vps = vpstate(plex); /* how do we compare with the other plexes? */ enum sdstates statemap = sdstatemap(plex, &sddowncount); /* get a map of the subdisk states */ if ((flags & setstate_force) && (oldstate == state)) /* we're there already, */ return 0; /* no change */ if (plex->state == plex_unallocated) /* no plex to do anything with, */ return 0; switch (state) { case plex_up: if ((plex->state == plex_initializing) /* we're initializing */ &&(statemap != sd_upstate)) /* but SDs aren't up yet */ return 0; /* do nothing */ /* We don't really care what our state was before * if we want to come up. We rely entirely on the * state of our subdisks and our volume */ switch (vps) { case volplex_onlyusdown: case volplex_alldown: /* another plex is down, and so are we */ if (statemap == sd_upstate) { /* all subdisks ready for action */ if ((plex->state == plex_init) /* we're brand spanking new */ &&(VOL[plex->volno].flags & VF_CONFIG_SETUPSTATE)) { /* and we consider that up */ /* Conceptually, an empty plex does not contain valid data, * but normally we'll see this state when we have just * created a plex, and it's either consistent from earlier, * or we don't care about the previous contents (we're going * to create a file system or use it for swap). * * We need to do this in one swell foop: on the next call * we will no longer be just empty. * * We'll still come back to this function for the remaining * plexes in the volume. They'll be up already, so that * doesn't change anything, but it's not worth the additional * code to stop doing it. */ struct volume *vol = &VOL[plex->volno]; int plexno; for (plexno = 0; plexno < vol->plexes; plexno++) PLEX[vol->plex[plexno]].state = plex_up; } plex->state = plex_up; /* bring up up, anyway */ } else plex->state = plex_down; break; case volplex_onlyusup: /* only we are up: others are down */ case volplex_onlyus: /* we're up and alone */ if ((statemap == sd_upstate) /* subdisks all up */ ||(statemap == sd_emptystate)) /* or all empty */ plex->state = plex_up; /* go for it */ else if ((statemap & (sd_upstate | sd_reborn)) == statemap) /* all up or reborn, */ plex->state = plex_flaky; else if (statemap & (sd_upstate | sd_reborn)) /* some up or reborn, */ plex->state = plex_degraded; /* so far no corruption */ else plex->state = plex_faulty; break; case volplex_otherup: /* another plex is up */ case volplex_otherupdown: /* other plexes are up and down */ if ((statemap == sd_upstate) /* subdisks all up */ ||(statemap == sd_emptystate) /* or all empty */ ) { /* Is the data in all subdisks valid? */ if (statemap == statemap & (sd_downstate | sd_rebornstate | sd_upstate)) break; /* yes, we can bring the plex up */ plex->state = plex_reviving; /* we need reviving */ return EAGAIN; } else plex->state = plex_faulty; /* still in error */ break; case volplex_allup: /* all plexes are up */ case volplex_someup: if ((statemap & (sd_upstate | sd_reborn)) == statemap) /* all up or reborn, */ break; /* no change */ else plex->state = plex_degraded; /* we're not all there */ } if (plex->state != oldstate) break; return 0; /* no change */ case plex_down: /* want to take it down */ if (((vps == volplex_onlyus) /* we're the only one up */ ||(vps == volplex_onlyusup)) /* we're the only one up */ &&(!(flags & setstate_force))) /* and we don't want to use force */ return 0; /* can't do it */ plex->state = state; /* do it */ break; /* This is only requested by the driver. * Trust ourselves */ case plex_faulty: plex->state = state; /* do it */ break; case plex_initializing: /* XXX consider what safeguards we need here */ if ((flags & setstate_force) == 0) return 0; plex->state = state; /* do it */ break; /* What's this? */ default: return 0; } printf("vinum: plex %s is %s\n", plex->name, plex_state(plex->state)); /* Now see what we have left, and whether * we're taking the volume down */ if (plex->volno >= 0) { /* we have a volume */ struct volume *vol = &VOL[plex->volno]; vps = vpstate(plex); /* get our combined state again */ if ((flags & setstate_norecurse) == 0) { /* we can recurse */ if ((vol->state == volume_up) && (vps == volplex_alldown)) /* and we're all down */ set_volume_state(plex->volno, volume_down, setstate_recursing); /* take our volume down */ else if ((vol->state == volume_down) && (vps & (volplex_otherup | volplex_onlyusup))) /* and at least one is up */ set_volume_state(plex->volno, volume_up, setstate_recursing); /* bring our volume up */ } } if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } /* Update the state of a plex dependent on its plexes. * Also rebuild the unmapped_region and defective_region table */ int set_volume_state(int volno, enum volumestate state, enum setstateflags flags) { int plexno; enum plexstates { plex_downstate = 1, /* found a plex which is down */ plex_degradedstate = 2, /* found a plex which is halfway up */ plex_upstate = 4 /* found a plex which is completely up */ }; int plexstatemap = 0; /* note the states we find */ struct volume *vol = &VOL[volno]; /* point to our volume */ if (vol->state == state) /* we're there already */ return 0; /* no change */ if (vol->state == volume_unallocated) /* no volume to do anything with, */ return 0; for (plexno = 0; plexno < vol->plexes; plexno++) { struct plex *plex = &PLEX[vol->plex[plexno]]; /* point to the plex */ switch (plex->state) { case plex_degraded: case plex_flaky: case plex_reviving: plexstatemap |= plex_degradedstate; break; case plex_up: plexstatemap |= plex_upstate; break; default: plexstatemap |= plex_downstate; break; } } if (state == volume_up) { /* want to come up */ if (plexstatemap & plex_upstate) { /* we have a plex which is completely up */ vol->state = volume_up; /* did it */ printf("vinum: volume %s is %s\n", vol->name, volume_state(vol->state)); if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } /* Here we should check whether we have enough * coverage for the complete volume. Writeme XXX */ } else if (state == volume_down) { /* want to go down */ if ((vol->opencount == 0) /* not open */ ||(flags & setstate_force != 0)) { /* or we're forcing */ vol->state = volume_down; printf("vinum: volume %s is %s\n", vol->name, volume_state(vol->state)); if ((flags & (setstate_configuring | setstate_recursing)) == 0) /* save config now */ save_config(); return 1; } } return 0; /* no change */ } /* Start an object, in other words do what we can to get it up. * This is called from vinumioctl (VINUMSTART). * Return error indications via ioctl_reply */ void start_object(struct vinum_ioctl_msg *data) { int status; int realstatus; /* what we really have */ int objindex = data->index; /* data gets overwritten */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */ switch (data->type) { case drive_object: status = set_drive_state(objindex, drive_up, setstate_none); realstatus = DRIVE[objindex].state == drive_up; /* set status on whether we really did it */ break; case sd_object: status = set_sd_state(objindex, sd_up, setstate_none); /* set state */ realstatus = SD[objindex].state == sd_up; /* set status on whether we really did it */ break; case plex_object: if (PLEX[objindex].state == plex_reviving) { /* reviving, */ ioctl_reply->error = revive_block(objindex); /* revive another block */ ioctl_reply->msg[0] = '\0'; /* no comment */ return; } status = set_plex_state(objindex, plex_up, setstate_none); realstatus = PLEX[objindex].state == plex_up; /* set status on whether we really did it */ break; case volume_object: status = set_volume_state(objindex, volume_up, setstate_none); realstatus = VOL[objindex].state == volume_up; /* set status on whether we really did it */ break; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); return; } /* There's no point in saying anything here: * the userland program does it better */ ioctl_reply->msg[0] = '\0'; if (realstatus == 0) /* couldn't do it */ ioctl_reply->error = EINVAL; else ioctl_reply->error = 0; } /* Stop an object, in other words do what we can to get it down * This is called from vinumioctl (VINUMSTOP). * Return error indications via ioctl_reply. */ void stop_object(struct vinum_ioctl_msg *data) { int status = 1; int objindex = data->index; /* save the number from change */ struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* format for returning replies */ switch (data->type) { case drive_object: status = set_drive_state(objindex, drive_down, data->force); break; case sd_object: status = set_sd_state(objindex, sd_down, data->force); break; case plex_object: status = set_plex_state(objindex, plex_down, data->force); break; case volume_object: status = set_volume_state(objindex, volume_down, data->force); break; default: ioctl_reply->error = EINVAL; strcpy(ioctl_reply->msg, "Invalid object type"); return; } ioctl_reply->msg[0] = '\0'; if (status == 0) /* couldn't do it */ ioctl_reply->error = EINVAL; else ioctl_reply->error = 0; } /* VINUM_SETSTATE ioctl: set an object state * msg is the message passed by the user */ void setstate(struct vinum_ioctl_msg *msg) { int sdno; struct sd *sd; struct plex *plex; struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) msg; /* format for returning replies */ switch (msg->state) { case object_down: stop_object(msg); break; case object_initializing: switch (msg->type) { case sd_object: sd = &SD[msg->index]; if ((msg->index >= vinum_conf.subdisks_used) || (sd->state == sd_unallocated)) { sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index); ioctl_reply->error = EFAULT; return; } set_sd_state(msg->index, sd_initializing, msg->force); if (sd->state != sd_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; } else ioctl_reply->error = 0; break; case plex_object: plex = &PLEX[msg->index]; if ((msg->index >= vinum_conf.plexes_used) || (plex->state == plex_unallocated)) { sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index); ioctl_reply->error = EFAULT; return; } set_plex_state(msg->index, plex_initializing, msg->force); if (plex->state != plex_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; } else { ioctl_reply->error = 0; for (sdno = 0; sdno < plex->subdisks; sdno++) { sd = &SD[plex->sdnos[sdno]]; set_sd_state(plex->sdnos[sdno], sd_initializing, msg->force); if (sd->state != sd_initializing) { strcpy(ioctl_reply->msg, "Can't set state"); ioctl_reply->error = EINVAL; break; } } } break; default: strcpy(ioctl_reply->msg, "Invalid object"); ioctl_reply->error = EINVAL; } break; case object_up: start_object(msg); } } diff --git a/sys/dev/vinum/vinumvar.h b/sys/dev/vinum/vinumvar.h index ca54f76aad02..ee347fca0be8 100644 --- a/sys/dev/vinum/vinumvar.h +++ b/sys/dev/vinum/vinumvar.h @@ -1,510 +1,517 @@ /*- * Copyright (c) 1997, 1998 * Nan Yang Computer Services Limited. All rights reserved. * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Nan Yang Computer * Services Limited. * 4. Neither the name of the Company nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: vinumvar.h,v 1.15 1998/08/14 06:36:41 grog Exp grog $ */ /* XXX gdb can't find our global pointers, so use this kludge to * point to them locally. Remove after testing */ #define BROKEN_GDB struct _vinum_conf *VC = &vinum_conf #include #include "vinumstate.h" /* Some configuration maxima. They're an enum because * we can't define global constants. Sorry about that. * * These aren't as bad as they look: most of them * are soft limits. Only the MAXCONFIG parameter is set in stone */ enum constants { VINUM_HEADER = 512, /* size of header on disk */ MAXCONFIGLINE = 1024, /* maximum size of a single config line */ /* XXX Do we still need this? */ MINVINUMSLICE = 1048576, /* minimum size of a slice */ CDEV_MAJOR = 91, /* major number for character device */ BDEV_MAJOR = 25, /* and block device */ ROUND_ROBIN_READPOL = -1, /* round robin read policy */ /* type field in minor number */ VINUM_VOLUME_TYPE = 0, VINUM_PLEX_TYPE = 1, VINUM_SD_TYPE = 2, VINUM_DRIVE_TYPE = 3, VINUM_SUPERDEV_TYPE = 4, /* super device. */ /* Shifts for the individual fields in the device */ VINUM_TYPE_SHIFT = 28, VINUM_VOL_SHIFT = 0, VINUM_PLEX_SHIFT = 16, VINUM_SD_SHIFT = 20, VINUM_VOL_WIDTH = 8, VINUM_PLEX_WIDTH = 3, VINUM_SD_WIDTH = 8, MAJORDEV_SHIFT = 8, /* Create a block device number */ #define VINUMBDEV(v,p,s,t) ((BDEV_MAJOR << MAJORDEV_SHIFT) \ | (v << VINUM_VOL_SHIFT) \ | (p << VINUM_PLEX_SHIFT) \ | (s << VINUM_SD_SHIFT) \ | (t << VINUM_TYPE_SHIFT) ) /* And a character device number */ #define VINUMCDEV(v,p,s,t) ((CDEV_MAJOR << MAJORDEV_SHIFT) \ | (v << VINUM_VOL_SHIFT) \ | (p << VINUM_PLEX_SHIFT) \ | (s << VINUM_SD_SHIFT) \ | (t << VINUM_TYPE_SHIFT) ) /* extract device type */ #define DEVTYPE(x) ((x >> VINUM_TYPE_SHIFT) & 7) /* extract volume number */ #define VOLNO(x) (x & ((1 << VINUM_VOL_WIDTH) - 1)) /* extract plex number */ #define PLEXNO(x) (VOL [VOLNO (x)].plex [(x >> VINUM_PLEX_SHIFT) & ((1 << VINUM_PLEX_WIDTH) - 1)]) /* extract subdisk number */ #define SDNO(x) (PLEX [PLEXNO (x)].sdnos [(x >> VINUM_SD_SHIFT) & ((1 << VINUM_SD_WIDTH) - 1)]) /* extract drive number */ #define DRIVENO(x) (SD [SDNO (x)].driveno) VINUM_SUPERDEV = VINUMBDEV(0, 0, 0, VINUM_SUPERDEV_TYPE), /* superdevice number */ /* the number of object entries to cater for initially, and also the * value by which they are incremented. It doesn't take long * to extend them, so theoretically we could start with 1 of each, but * it's untidy to allocate such small areas. These values are * probably too small. */ INITIAL_DRIVES = 4, INITIAL_VOLUMES = 4, INITIAL_PLEXES = 8, INITIAL_SUBDISKS = 16, INITIAL_SUBDISKS_IN_PLEX = 4, /* number of subdisks to allocate to a plex */ INITIAL_SUBDISKS_IN_DRIVE = 4, /* number of subdisks to allocate to a drive */ INITIAL_DRIVE_FREELIST = 16, /* number of entries in drive freelist */ PLEX_REGION_TABLE_SIZE = 8, /* number of entries in plex region tables */ INITIAL_LOCKS = 8, /* number of locks to allocate to a volume */ DEFAULT_REVIVE_BLOCKSIZE = 32768, /* size of block to transfer in one op */ }; /* device numbers */ /* * 31 30 28 27 20 19 18 16 15 8 7 0 * |-----------------------------------------------------------------------------------------------| * |X | Type | Subdisk number | X| Plex | Major number | volume number | * |-----------------------------------------------------------------------------------------------| * * 0x2 03 1 19 06 */ struct devcode { /* CARE. These fields assume a big-endian word. On a * little-endian system, they're the wrong way around */ unsigned volume:8; /* up to 256 volumes */ unsigned major:8; /* this is where the major number fits */ unsigned plex:3; /* up to 8 plexes per volume */ unsigned unused:1; /* up for grabs */ unsigned sd:8; /* up to 256 subdisks per plex */ unsigned type:3; /* type of object */ /* type field VINUM_VOLUME = 0, VINUM_PLEX = 1, VINUM_SUBDISK = 2, VINUM_DRIVE = 3, VINUM_SUPERDEV = 4, */ unsigned signbit:1; /* to make 32 bits */ }; #define VINUM_DIR "/dev/vinum" #define VINUM_RDIR "/dev/rvinum" #define VINUM_SUPERDEV_NAME VINUM_DIR"/control" #define MAXDRIVENAME 32 /* maximum length of a device name */ #define MAXSDNAME 64 /* maximum length of a subdisk name */ #define MAXPLEXNAME 64 /* maximum length of a plex name */ #define MAXVOLNAME 64 /* maximum length of a volume name */ #define MAXNAME 64 /* maximum length of any name */ #define MAXVOLPLEX 8 /* maximum number of plexes in a volume */ /* Flags for all objects. Most of them only apply to * specific objects, but we have space for all in any * 32 bit flags word. */ enum objflags { VF_LOCKED = 1, /* somebody has locked access to this object */ VF_LOCKING = 2, /* we want access to this object */ VF_WRITETHROUGH = 8, /* volume: write through */ VF_INITED = 0x10, /* unit has been initialized */ VF_WLABEL = 0x20, /* label area is writable */ VF_LABELLING = 0x40, /* unit is currently being labelled */ VF_WANTED = 0x80, /* someone is waiting to obtain a lock */ VF_RAW = 0x100, /* raw volume (no file system) */ VF_LOADED = 0x200, /* module is loaded */ VF_CONFIGURING = 0x400, /* somebody is changing the config */ VF_WILL_CONFIGURE = 0x800, /* somebody wants to change the config */ VF_CONFIG_INCOMPLETE = 0x1000, /* haven't finished changing the config */ VF_CONFIG_SETUPSTATE = 0x2000, /* set a volume up if all plexes are empty */ VF_READING_CONFIG = 0x4000, /* we're reading config database from disk */ VF_KERNELOP = 0x8000, /* we're performing ops from kernel space */ + VF_DIRTYCONFIG = 0x10000, /* config needs updating */ }; /* Global configuration information for the vinum subsystem */ struct _vinum_conf { /* Pointers to vinum structures */ struct drive *drive; struct sd *sd; struct plex *plex; struct volume *volume; /* the number allocated */ int drives_allocated; int subdisks_allocated; int plexes_allocated; int volumes_allocated; /* and the number currently in use */ int drives_used; int subdisks_used; int plexes_used; int volumes_used; int flags; int opencount; /* number of times we've been opened */ #if DEBUG int lastrq; struct buf *lastbuf; + struct rqinfo **rqipp; + struct rqinfo *rqinfop; #endif }; /* Use these defines to simplify code */ #define DRIVE vinum_conf.drive #define SD vinum_conf.sd #define PLEX vinum_conf.plex #define VOL vinum_conf.volume #define VFLAGS vinum_conf.flags /* Slice header * Vinum drives start with this structure: * - * Sector + *\ Sector * |--------------------------------------| * | PDP-11 memorial boot block | 0 * |--------------------------------------| * | Disk label, maybe | 1 * |--------------------------------------| * | Slice definition (vinum_hdr) | 2 * |--------------------------------------| * | | * | Configuration info, first copy | 3 * | | * |--------------------------------------| * | | * | Configuration info, second copy | 3 + size of config * | | * |--------------------------------------| */ /* Sizes and offsets of our information */ enum { VINUM_LABEL_OFFSET = 4096, /* offset of vinum label */ VINUMHEADERLEN = 512, /* size of vinum label */ VINUM_CONFIG_OFFSET = 4608, /* offset of first config copy */ MAXCONFIG = 65536, /* and size of config copy */ DATASTART = (MAXCONFIG * 2 + VINUM_CONFIG_OFFSET) / DEV_BSIZE /* this is where the data starts */ }; /* hostname is 256 bytes long, but we don't need to shlep * multiple copies in vinum. We use the host name just * to identify this system, and 32 bytes should be ample * for that purpose */ #define VINUMHOSTNAMELEN 32 struct vinum_label { char sysname[VINUMHOSTNAMELEN]; /* system name at time of creation */ char name[MAXDRIVENAME]; /* our name of the drive */ struct timeval date_of_birth; /* the time it was created */ struct timeval last_update; /* and the time of last update */ off_t drive_size; /* total size in bytes of the drive. * This value includes the headers */ }; struct vinum_hdr { long long magic; /* we're long on magic numbers */ /* XXX Get these right for big-endian */ #define VINUM_MAGIC 22322600044678729LL /* should be this */ #define VINUM_NOMAGIC 22322600044678990LL /* becomes this after obliteration */ int config_length; /* size in bytes of each copy of the * configuration info. * This must be a multiple of the sector size. */ struct vinum_label label; /* unique label */ }; /* Information returned from read_drive_label */ enum drive_label_info { DL_CANT_OPEN, /* invalid partition */ DL_NOT_OURS, /* valid partition, but no vinum label */ DL_DELETED_LABEL, /* valid partition, deleted label found */ DL_WRONG_DRIVE, /* drive name doesn't match */ DL_OURS /* valid partition and label found */ }; /*** Drive definitions ***/ /* A drive corresponds to a disk slice. We use a different term to show * the difference in usage: it doesn't have to be a slice, and could * theroretically be a complete, unpartitioned disk */ struct drive { enum drivestate state; /* current state */ int subdisks_allocated; /* number of entries in sd */ int subdisks_used; /* and the number used */ int blocksize; /* size of fs blocks */ u_int64_t sectors_available; /* number of sectors still available */ int secsperblock; int lasterror; /* last error on drive */ int driveno; /* index of drive in vinum_conf */ int opencount; /* number of up subdisks */ u_int64_t reads; /* number of reads on this drive */ u_int64_t writes; /* number of writes on this drive */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ dev_t dev; /* and device number */ char devicename[MAXDRIVENAME]; /* name of the slice it's on */ struct vnode *vp; /* vnode pointer */ struct proc *p; struct vinum_label label; /* and the label information */ struct partinfo partinfo; /* partition information */ int freelist_size; /* number of entries alloced in free list */ int freelist_entries; /* number of entries used in free list */ struct drive_freelist { /* sorted list of free space on drive */ u_int64_t offset; long sectors; } *freelist; }; /*** Subdisk definitions ***/ struct sd { enum sdstate state; /* state */ /* offsets in blocks */ int64_t driveoffset; /* offset on drive */ int64_t plexoffset; /* offset in plex */ u_int64_t sectors; /* and length in sectors */ int plexno; /* index of plex, if it belongs */ int driveno; /* index of the drive on which it is located */ int sdno; /* our index in vinum_conf */ int pid; /* pid of process which opened us */ u_int64_t reads; /* number of reads on this subdisk */ u_int64_t writes; /* number of writes on this subdisk */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ char name[MAXSDNAME]; /* name of subdisk */ }; /*** Plex definitions ***/ /* kinds of plex organization */ enum plexorg { plex_disorg, /* disorganized */ plex_concat, /* concatenated plex */ plex_striped, /* striped plex */ plex_raid5 /* RAID5 plex */ }; /* Region in plex (either defective or unmapped) */ struct plexregion { u_int64_t offset; /* start of region */ u_int64_t length; /* length */ }; struct plex { enum plexorg organization; /* Plex organization */ enum plexstate state; /* and current state */ u_int64_t length; /* total length of plex (max offset) */ int flags; int stripesize; /* size of stripe or raid band, in sectors */ int subdisks; /* number of associated subdisks */ int subdisks_allocated; /* number of subdisks allocated space for */ int *sdnos; /* list of component subdisks */ int plexno; /* index of plex in vinum_conf */ int volno; /* index of volume */ int volplexno; /* number of plex in volume */ int pid; /* pid of process which opened us */ /* Lock information */ int locks; /* number of locks used */ int alloclocks; /* number of locks allocated */ struct rangelock *lock; /* ranges of locked addresses */ /* Statistics */ u_int64_t reads; /* number of reads on this plex */ u_int64_t writes; /* number of writes on this plex */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ u_int64_t multiblock; /* requests that needed more than one block */ u_int64_t multistripe; /* requests that needed more than one stripe */ /* revive parameters */ u_int64_t revived; /* block number of current revive request */ int revive_blocksize; /* revive block size (bytes) */ int revive_interval; /* and time to wait between transfers */ struct request *waitlist; /* list of requests waiting on revive op */ /* geometry control */ int defective_regions; /* number of regions which are defective */ int defective_region_count; /* number of entries in defective_region */ struct plexregion *defective_region; /* list of offset/length pairs: defective sds */ int unmapped_regions; /* number of regions which are missing */ int unmapped_region_count; /* number of entries in unmapped_region */ struct plexregion *unmapped_region; /* list of offset/length pairs: missing sds */ char name[MAXPLEXNAME]; /* name of plex */ }; /*** Volume definitions ***/ #define MAXPLEX 8 /* maximum number of plexes */ struct volume { enum volumestate state; /* current state */ int plexes; /* number of plexes */ int preferred_plex; /* plex to read from, -1 for round-robin */ int last_plex_read; /* index of plex used for last read, * for round-robin */ dev_t devno; /* device number */ int flags; /* status and configuration flags */ int opencount; /* number of opens (all the same process) */ int openflags; /* flags supplied to last open(2) */ u_int64_t size; /* size of volume */ int disk; /* disk index */ int blocksize; /* logical block size */ int active; /* number of outstanding requests active */ int subops; /* and the number of suboperations */ pid_t pid; /* pid of locker */ /* Statistics */ u_int64_t bytes_read; /* number of bytes read */ u_int64_t bytes_written; /* number of bytes written */ u_int64_t reads; /* number of reads on this volume */ u_int64_t writes; /* number of writes on this volume */ u_int64_t recovered_reads; /* reads recovered from another plex */ /* Unlike subdisks in the plex, space for the plex pointers is static */ int plex[MAXPLEX]; /* index of plexes */ char name[MAXVOLNAME]; /* name of volume */ struct disklabel label; /* for DIOCGPART */ }; /* Table expansion. Expand table, which contains oldcount * entries of type element, by increment entries, and change * oldcount accordingly */ #define EXPAND(table, element, oldcount, increment) \ { \ expand_table ((void **) &table, \ oldcount * sizeof (element), \ (oldcount + increment) * sizeof (element) ); \ oldcount += increment; \ } /* Information on vinum's memory usage */ struct meminfo { int mallocs; /* number of malloced blocks */ int total_malloced; /* total amount malloced */ int highwater; /* maximum number of mallocs */ struct mc *malloced; /* pointer to kernel table */ }; struct mc { int seq; int size; short line; short flags; #define ALLOC_KVA 1 /* allocated via kva calls */ int *databuf; /* really vm_object_t */ caddr_t address; char file[16]; }; /* These enums are used by the state transition * routines. They're in bit map format: * * Bit 0: Other plexes in the volume are down * Bit 1: Other plexes in the volume are up * Bit 2: The current plex is up * Maybe they should be local to * state.c */ enum volplexstate { volplex_onlyusdown = 0, /* we're the only plex, and we're down */ volplex_alldown, /* 1: another plex is down, and so are we */ volplex_otherup, /* 2: another plex is up */ volplex_otherupdown, /* other plexes are up and down */ volplex_onlyus, /* 4: we're up and alone */ volplex_onlyusup, /* only we are up, others are down */ volplex_allup, /* all plexes are up */ volplex_someup /* some plexes are up, including us */ }; /* state map for plex */ enum sdstates { sd_emptystate = 1, sd_downstate = 2, /* found an SD which is down */ sd_crashedstate = 4, /* found an SD which is crashed */ sd_obsoletestate = 8, /* found an SD which is obsolete */ sd_stalestate = 16, /* found an SD which is stale */ sd_rebornstate = 32, /* found an SD which is reborn */ sd_upstate = 64, /* found an SD which is up */ sd_initstate = 128, /* found an SD which is init */ sd_otherstate = 256 /* found an SD in some other state */ }; /* This is really just a parameter to pass to * set__state, but since it needs to be known * in the external definitions, we need to define * it here */ enum setstateflags { setstate_none = 0, /* no flags */ setstate_force = 1, /* force the state change */ setstate_configuring = 2, /* we're currently configuring, don't save */ setstate_recursing = 4, /* we're called from another setstate function */ - setstate_norecurse = 8 /* don't call other setstate functions */ + setstate_norecurse = 8, /* don't call other setstate functions */ + setstate_noupdate = 16 /* don't update config */ }; #ifdef DEBUG /* Debugging stuff */ #define DEBUG_ADDRESSES 1 #define DEBUG_NUMOUTPUT 2 +#define DEBUG_RESID 4 /* go into debugger in complete_rqe */ +#define DEBUG_LASTREQS 8 /* keep a circular buffer of last requests */ +#define DEBUG_REMOTEGDB 256 /* go into remote gdb */ #endif