/**************************************************************************** * Set up the data structures describing the spare disks in the array. * Recall from the above comment that the spare disk descriptors are stored * in row zero, which is specially expanded to hold them. ****************************************************************************/ int rf_ConfigureSpareDisks(RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr, RF_Config_t * cfgPtr) { int i, ret; unsigned int bs; RF_RaidDisk_t *disks; int num_spares_done; num_spares_done = 0; /* * The space for the spares should have already been allocated by * ConfigureDisks(). */ disks = &raidPtr->Disks[0][raidPtr->numCol]; for (i = 0; i < raidPtr->numSpare; i++) { ret = rf_ConfigureDisk(raidPtr, &cfgPtr->spare_names[i][0], &disks[i], 0, raidPtr->numCol + i); if (ret) goto fail; if (disks[i].status != rf_ds_optimal) { RF_ERRORMSG1("Warning: spare disk %s failed TUR\n", &cfgPtr->spare_names[i][0]); } else { /* Change status to spare. */ disks[i].status = rf_ds_spare; DPRINTF6("Spare Disk %d: dev %s numBlocks %ld" " blockSize %d (%ld MB).\n", i, disks[i].devname, (long int) disks[i].numBlocks, disks[i].blockSize, (long int) disks[i].numBlocks * disks[i].blockSize / 1024 / 1024); } num_spares_done++; } /* Check sizes and block sizes on spare disks. */ bs = 1 << raidPtr->logBytesPerSector; for (i = 0; i < raidPtr->numSpare; i++) { if (disks[i].blockSize != bs) { RF_ERRORMSG3("Block size of %d on spare disk %s is" " not the same as on other disks (%d).\n", disks[i].blockSize, disks[i].devname, bs); ret = EINVAL; goto fail; } if (disks[i].numBlocks < raidPtr->sectorsPerDisk) { RF_ERRORMSG3("Spare disk %s (%llu blocks) is too small" " to serve as a spare (need %llu blocks).\n", disks[i].devname, disks[i].numBlocks, raidPtr->sectorsPerDisk); ret = EINVAL; goto fail; } else if (disks[i].numBlocks > raidPtr->sectorsPerDisk) { RF_ERRORMSG2("Warning: truncating spare disk" " %s to %llu blocks.\n", disks[i].devname, raidPtr->sectorsPerDisk); disks[i].numBlocks = raidPtr->sectorsPerDisk; } } return (0); fail: /* * Release the hold on the main components. We've failed to allocate * a spare, and since we're failing, we need to free things... * * XXX Failing to allocate a spare is *not* that big of a deal... * We *can* survive without it, if need be, esp. if we get hot * adding working. * If we don't fail out here, then we need a way to remove this spare... * That should be easier to do here than if we are "live"... */ rf_UnconfigureVnodes(raidPtr); return (ret); }
/**************************************************************************************** * set up the data structures describing the spare disks in the array * recall from the above comment that the spare disk descriptors are stored * in row zero, which is specially expanded to hold them. ***************************************************************************************/ int rf_ConfigureSpareDisks( RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr, RF_Config_t * cfgPtr) { char buf[256]; int r, c, i, ret; RF_DiskOp_t *rdcap_op = NULL, *tur_op = NULL; unsigned bs; RF_RaidDisk_t *disks; int num_spares_done; struct proc *proc; #if !defined(__NetBSD__) && !defined(__OpenBSD__) ret = rf_SCSI_AllocReadCapacity(&rdcap_op); if (ret) goto fail; ret = rf_SCSI_AllocTUR(&tur_op); if (ret) goto fail; #endif /* !__NetBSD__ && !__OpenBSD__ */ num_spares_done = 0; proc = raidPtr->proc; /* The space for the spares should have already been allocated by * ConfigureDisks() */ disks = &raidPtr->Disks[0][raidPtr->numCol]; for (i = 0; i < raidPtr->numSpare; i++) { ret = rf_ConfigureDisk(raidPtr, &cfgPtr->spare_names[i][0], &disks[i], rdcap_op, tur_op, cfgPtr->spare_devs[i], 0, raidPtr->numCol + i); if (ret) goto fail; if (disks[i].status != rf_ds_optimal) { RF_ERRORMSG1("Warning: spare disk %s failed TUR\n", buf); } else { disks[i].status = rf_ds_spare; /* change status to * spare */ DPRINTF6("Spare Disk %d: dev %s numBlocks %ld blockSize %d (%ld MB)\n", i, disks[i].devname, (long int) disks[i].numBlocks, disks[i].blockSize, (long int) disks[i].numBlocks * disks[i].blockSize / 1024 / 1024); } num_spares_done++; } #if (defined(__NetBSD__) || defined(__OpenBSD__)) && (_KERNEL) #else rf_SCSI_FreeDiskOp(rdcap_op, 1); rdcap_op = NULL; rf_SCSI_FreeDiskOp(tur_op, 0); tur_op = NULL; #endif /* check sizes and block sizes on spare disks */ bs = 1 << raidPtr->logBytesPerSector; for (i = 0; i < raidPtr->numSpare; i++) { if (disks[i].blockSize != bs) { RF_ERRORMSG3("Block size of %d on spare disk %s is not the same as on other disks (%d)\n", disks[i].blockSize, disks[i].devname, bs); ret = EINVAL; goto fail; } if (disks[i].numBlocks < raidPtr->sectorsPerDisk) { RF_ERRORMSG3("Spare disk %s (%d blocks) is too small to serve as a spare (need %ld blocks)\n", disks[i].devname, disks[i].blockSize, (long int) raidPtr->sectorsPerDisk); ret = EINVAL; goto fail; } else if (disks[i].numBlocks > raidPtr->sectorsPerDisk) { RF_ERRORMSG2("Warning: truncating spare disk %s to %ld blocks\n", disks[i].devname, (long int) raidPtr->sectorsPerDisk); disks[i].numBlocks = raidPtr->sectorsPerDisk; } } return (0); fail: #if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL) /* Release the hold on the main components. We've failed to allocate * a spare, and since we're failing, we need to free things.. */ for (r = 0; r < raidPtr->numRow; r++) { for (c = 0; c < raidPtr->numCol; c++) { /* Cleanup.. */ #ifdef DEBUG printf("Cleaning up row: %d col: %d\n", r, c); #endif if (raidPtr->raid_cinfo[r][c].ci_vp) { (void) vn_close(raidPtr->raid_cinfo[r][c].ci_vp, FREAD | FWRITE, proc->p_ucred, proc); } } } for (i = 0; i < raidPtr->numSpare; i++) { /* Cleanup.. */ #ifdef DEBUG printf("Cleaning up spare: %d\n", i); #endif if (raidPtr->raid_cinfo[0][raidPtr->numCol + i].ci_vp) { (void) vn_close(raidPtr->raid_cinfo[0][raidPtr->numCol + i].ci_vp, FREAD | FWRITE, proc->p_ucred, proc); } } #else if (rdcap_op) rf_SCSI_FreeDiskOp(rdcap_op, 1); if (tur_op) rf_SCSI_FreeDiskOp(tur_op, 0); #endif return (ret); }
int rf_add_hot_spare(RF_Raid_t *raidPtr, RF_SingleComponent_t *sparePtr) { RF_RaidDisk_t *disks; RF_DiskQueue_t *spareQueues; int ret; unsigned int bs; int spare_number; #if 0 printf("Just in rf_add_hot_spare: %d.\n", raidPtr->numSpare); printf("Num col: %d.\n", raidPtr->numCol); #endif if (raidPtr->numSpare >= RF_MAXSPARE) { RF_ERRORMSG1("Too many spares: %d.\n", raidPtr->numSpare); return(EINVAL); } RF_LOCK_MUTEX(raidPtr->mutex); /* The beginning of the spares... */ disks = &raidPtr->Disks[0][raidPtr->numCol]; spare_number = raidPtr->numSpare; ret = rf_ConfigureDisk(raidPtr, sparePtr->component_name, &disks[spare_number], 0, raidPtr->numCol + spare_number); if (ret) goto fail; if (disks[spare_number].status != rf_ds_optimal) { RF_ERRORMSG1("Warning: spare disk %s failed TUR.\n", sparePtr->component_name); ret = EINVAL; goto fail; } else { disks[spare_number].status = rf_ds_spare; DPRINTF6("Spare Disk %d: dev %s numBlocks %ld blockSize %d" " (%ld MB).\n", spare_number, disks[spare_number].devname, (long int) disks[spare_number].numBlocks, disks[spare_number].blockSize, (long int) disks[spare_number].numBlocks * disks[spare_number].blockSize / 1024 / 1024); } /* Check sizes and block sizes on the spare disk. */ bs = 1 << raidPtr->logBytesPerSector; if (disks[spare_number].blockSize != bs) { RF_ERRORMSG3("Block size of %d on spare disk %s is not" " the same as on other disks (%d).\n", disks[spare_number].blockSize, disks[spare_number].devname, bs); ret = EINVAL; goto fail; } if (disks[spare_number].numBlocks < raidPtr->sectorsPerDisk) { RF_ERRORMSG3("Spare disk %s (%llu blocks) is too small to serve" " as a spare (need %llu blocks).\n", disks[spare_number].devname, disks[spare_number].numBlocks, raidPtr->sectorsPerDisk); ret = EINVAL; goto fail; } else { if (disks[spare_number].numBlocks > raidPtr->sectorsPerDisk) { RF_ERRORMSG2("Warning: truncating spare disk %s to %llu" " blocks.\n", disks[spare_number].devname, raidPtr->sectorsPerDisk); disks[spare_number].numBlocks = raidPtr->sectorsPerDisk; } } spareQueues = &raidPtr->Queues[0][raidPtr->numCol]; ret = rf_ConfigureDiskQueue(raidPtr, &spareQueues[spare_number], 0, raidPtr->numCol + spare_number, raidPtr->qType, raidPtr->sectorsPerDisk, raidPtr->Disks[0][raidPtr->numCol + spare_number].dev, raidPtr->maxOutstanding, &raidPtr->shutdownList, raidPtr->cleanupList); raidPtr->numSpare++; RF_UNLOCK_MUTEX(raidPtr->mutex); return (0); fail: RF_UNLOCK_MUTEX(raidPtr->mutex); return(ret); }