/**************************************************************************************** * * initialize the disks comprising the array * * We want the spare disks to have regular row,col numbers so that we can easily * substitue a spare for a failed disk. But, the driver code assumes throughout * that the array contains numRow by numCol _non-spare_ disks, so it's not clear * how to fit in the spares. This is an unfortunate holdover from raidSim. The * quick and dirty fix is to make row zero bigger than the rest, and put all the * spares in it. This probably needs to get changed eventually. * ***************************************************************************************/ int rf_ConfigureDisks( RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr, RF_Config_t * cfgPtr) { RF_RaidDisk_t **disks; RF_SectorCount_t min_numblks = (RF_SectorCount_t) 0x7FFFFFFFFFFFLL; RF_RowCol_t r, c; int bs, ret; unsigned i, count, foundone = 0, numFailuresThisRow; RF_DiskOp_t *rdcap_op = NULL, *tur_op = NULL; int num_rows_done, num_cols_done; struct proc *proc = 0; #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_rows_done = 0; num_cols_done = 0; RF_CallocAndAdd(disks, raidPtr->numRow, sizeof(RF_RaidDisk_t *), (RF_RaidDisk_t **), raidPtr->cleanupList); if (disks == NULL) { ret = ENOMEM; goto fail; } raidPtr->Disks = disks; proc = raidPtr->proc; /* Blah XXX */ /* get space for the device-specific stuff... */ RF_CallocAndAdd(raidPtr->raid_cinfo, raidPtr->numRow, sizeof(struct raidcinfo *), (struct raidcinfo **), raidPtr->cleanupList); if (raidPtr->raid_cinfo == NULL) { ret = ENOMEM; goto fail; } for (r = 0; r < raidPtr->numRow; r++) { numFailuresThisRow = 0; RF_CallocAndAdd(disks[r], raidPtr->numCol + ((r == 0) ? raidPtr->numSpare : 0), sizeof(RF_RaidDisk_t), (RF_RaidDisk_t *), raidPtr->cleanupList); if (disks[r] == NULL) { ret = ENOMEM; goto fail; } /* get more space for device specific stuff.. */ RF_CallocAndAdd(raidPtr->raid_cinfo[r], raidPtr->numCol + ((r == 0) ? raidPtr->numSpare : 0), sizeof(struct raidcinfo), (struct raidcinfo *), raidPtr->cleanupList); if (raidPtr->raid_cinfo[r] == NULL) { ret = ENOMEM; goto fail; } for (c = 0; c < raidPtr->numCol; c++) { ret = rf_ConfigureDisk(raidPtr, &cfgPtr->devnames[r][c][0], &disks[r][c], rdcap_op, tur_op, cfgPtr->devs[r][c], r, c); if (ret) goto fail; if (disks[r][c].status != rf_ds_optimal) { numFailuresThisRow++; } else { if (disks[r][c].numBlocks < min_numblks) min_numblks = disks[r][c].numBlocks; DPRINTF7("Disk at row %d col %d: dev %s numBlocks %ld blockSize %d (%ld MB)\n", r, c, disks[r][c].devname, (long int) disks[r][c].numBlocks, disks[r][c].blockSize, (long int) disks[r][c].numBlocks * disks[r][c].blockSize / 1024 / 1024); } num_cols_done++; } /* XXX fix for n-fault tolerant */ if (numFailuresThisRow > 0) raidPtr->status[r] = rf_rs_degraded; num_rows_done++; } #if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL) /* we do nothing */ #else rf_SCSI_FreeDiskOp(rdcap_op, 1); rdcap_op = NULL; rf_SCSI_FreeDiskOp(tur_op, 0); tur_op = NULL; #endif /* all disks must be the same size & have the same block size, bs must * be a power of 2 */ bs = 0; for (foundone = r = 0; !foundone && r < raidPtr->numRow; r++) { for (c = 0; !foundone && c < raidPtr->numCol; c++) { if (disks[r][c].status == rf_ds_optimal) { bs = disks[r][c].blockSize; foundone = 1; } } } if (!foundone) { RF_ERRORMSG("RAIDFRAME: Did not find any live disks in the array.\n"); ret = EINVAL; goto fail; } for (count = 0, i = 1; i; i <<= 1) if (bs & i) count++; if (count != 1) { RF_ERRORMSG1("Error: block size on disks (%d) must be a power of 2\n", bs); ret = EINVAL; goto fail; } for (r = 0; r < raidPtr->numRow; r++) { for (c = 0; c < raidPtr->numCol; c++) { if (disks[r][c].status == rf_ds_optimal) { if (disks[r][c].blockSize != bs) { RF_ERRORMSG2("Error: block size of disk at r %d c %d different from disk at r 0 c 0\n", r, c); ret = EINVAL; goto fail; } if (disks[r][c].numBlocks != min_numblks) { RF_ERRORMSG3("WARNING: truncating disk at r %d c %d to %d blocks\n", r, c, (int) min_numblks); disks[r][c].numBlocks = min_numblks; } } } } raidPtr->sectorsPerDisk = min_numblks; raidPtr->logBytesPerSector = ffs(bs) - 1; raidPtr->bytesPerSector = bs; raidPtr->sectorMask = bs - 1; return (0); fail: #if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(_KERNEL) 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); } } } /* Space allocated for raid_vpp will get cleaned up at some other * point */ /* XXX Need more #ifdefs in the above... */ #else if (rdcap_op) rf_SCSI_FreeDiskOp(rdcap_op, 1); if (tur_op) rf_SCSI_FreeDiskOp(tur_op, 0); #endif return (ret); }
/**************************************************************************** * * Initialize the disks comprising the array. * * We want the spare disks to have regular row,col numbers so that we can * easily substitue a spare for a failed disk. But, the driver code assumes * throughout that the array contains numRow by numCol _non-spare_ disks, so * it's not clear how to fit in the spares. This is an unfortunate holdover * from raidSim. The quick and dirty fix is to make row zero bigger than the * rest, and put all the spares in it. This probably needs to get changed * eventually. * ****************************************************************************/ int rf_ConfigureDisks(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, RF_Config_t *cfgPtr) { RF_RaidDisk_t **disks; RF_SectorCount_t min_numblks = (RF_SectorCount_t) 0x7FFFFFFFFFFFLL; RF_RowCol_t r, c; int bs, ret; unsigned i, count, foundone = 0, numFailuresThisRow; int force; force = cfgPtr->force; ret = rf_AllocDiskStructures(raidPtr, cfgPtr); if (ret) goto fail; disks = raidPtr->Disks; for (r = 0; r < raidPtr->numRow; r++) { numFailuresThisRow = 0; for (c = 0; c < raidPtr->numCol; c++) { ret = rf_ConfigureDisk(raidPtr, &cfgPtr->devnames[r][c][0], &disks[r][c], r, c); if (ret) goto fail; if (disks[r][c].status == rf_ds_optimal) { raidread_component_label( raidPtr->raid_cinfo[r][c].ci_dev, raidPtr->raid_cinfo[r][c].ci_vp, &raidPtr->raid_cinfo[r][c].ci_label); } if (disks[r][c].status != rf_ds_optimal) { numFailuresThisRow++; } else { if (disks[r][c].numBlocks < min_numblks) min_numblks = disks[r][c].numBlocks; DPRINTF7("Disk at row %d col %d: dev %s" " numBlocks %ld blockSize %d (%ld MB)\n", r, c, disks[r][c].devname, (long int) disks[r][c].numBlocks, disks[r][c].blockSize, (long int) disks[r][c].numBlocks * disks[r][c].blockSize / 1024 / 1024); } } /* XXX Fix for n-fault tolerant. */ /* * XXX This should probably check to see how many failures * we can handle for this configuration ! */ if (numFailuresThisRow > 0) raidPtr->status[r] = rf_rs_degraded; } /* * All disks must be the same size & have the same block size, bs must * be a power of 2. */ bs = 0; for (foundone = r = 0; !foundone && r < raidPtr->numRow; r++) { for (c = 0; !foundone && c < raidPtr->numCol; c++) { if (disks[r][c].status == rf_ds_optimal) { bs = disks[r][c].blockSize; foundone = 1; } } } if (!foundone) { RF_ERRORMSG("RAIDFRAME: Did not find any live disks in" " the array.\n"); ret = EINVAL; goto fail; } for (count = 0, i = 1; i; i <<= 1) if (bs & i) count++; if (count != 1) { RF_ERRORMSG1("Error: block size on disks (%d) must be a" " power of 2.\n", bs); ret = EINVAL; goto fail; } if (rf_CheckLabels(raidPtr, cfgPtr)) { printf("raid%d: There were fatal errors\n", raidPtr->raidid); if (force != 0) { printf("raid%d: Fatal errors being ignored.\n", raidPtr->raidid); } else { ret = EINVAL; goto fail; } } for (r = 0; r < raidPtr->numRow; r++) { for (c = 0; c < raidPtr->numCol; c++) { if (disks[r][c].status == rf_ds_optimal) { if (disks[r][c].blockSize != bs) { RF_ERRORMSG2("Error: block size of" " disk at r %d c %d different from" " disk at r 0 c 0.\n", r, c); ret = EINVAL; goto fail; } if (disks[r][c].numBlocks != min_numblks) { RF_ERRORMSG3("WARNING: truncating disk" " at r %d c %d to %d blocks.\n", r, c, (int) min_numblks); disks[r][c].numBlocks = min_numblks; } } } } raidPtr->sectorsPerDisk = min_numblks; raidPtr->logBytesPerSector = ffs(bs) - 1; raidPtr->bytesPerSector = bs; raidPtr->sectorMask = bs - 1; return (0); fail: rf_UnconfigureVnodes(raidPtr); return (ret); }