diff -ruP raidframe.scottl/Makefile raidframe/Makefile --- raidframe.scottl/Makefile Thu Jan 1 01:00:00 1970 +++ raidframe/Makefile Mon Jan 12 20:57:24 2004 @@ -0,0 +1,73 @@ +# $FreeBSD: src/sys/modules/raidframe/Makefile,v 1.2 2003/12/29 09:03:38 bde Exp $ + +KMOD= raidframe + +SRCS= rf_acctrace.c +SRCS+= rf_alloclist.c +SRCS+= rf_aselect.c +SRCS+= rf_callback.c +SRCS+= rf_chaindecluster.c +#SRCS+= rf_copyback.c +SRCS+= rf_cvscan.c +SRCS+= rf_dagdegrd.c +SRCS+= rf_dagdegwr.c +SRCS+= rf_dagffrd.c +SRCS+= rf_dagffwr.c +SRCS+= rf_dagfuncs.c +SRCS+= rf_dagutils.c +SRCS+= rf_debugMem.c +SRCS+= rf_debugprint.c +SRCS+= rf_decluster.c +SRCS+= rf_declusterPQ.c +#SRCS+= rf_diskqueue.c +#SRCS+= rf_disks.c +SRCS+= rf_driver.c +SRCS+= rf_engine.c +SRCS+= rf_evenodd.c +SRCS+= rf_evenodd_dagfuncs.c +SRCS+= rf_evenodd_dags.c +SRCS+= rf_fifo.c +SRCS+= rf_interdecluster.c +SRCS+= rf_invertq.c +SRCS+= rf_layout.c +SRCS+= rf_map.c +SRCS+= rf_mcpair.c +SRCS+= rf_memchunk.c +SRCS+= rf_nwayxor.c +SRCS+= rf_options.c +SRCS+= rf_paritylog.c +SRCS+= rf_paritylogDiskMgr.c +SRCS+= rf_paritylogging.c +SRCS+= rf_parityloggingdags.c +SRCS+= rf_parityscan.c rf_pq.c +SRCS+= rf_pqdeg.c +SRCS+= rf_pqdegdags.c +SRCS+= rf_psstatus.c +SRCS+= rf_raid0.c +SRCS+= rf_raid1.c +SRCS+= rf_raid4.c +SRCS+= rf_raid5.c +SRCS+= rf_raid5_rotatedspare.c +SRCS+= rf_reconbuffer.c +SRCS+= rf_reconmap.c +#SRCS+= rf_reconstruct.c +SRCS+= rf_reconutil.c +SRCS+= rf_revent.c +SRCS+= rf_shutdown.c +SRCS+= rf_sstf.c +SRCS+= rf_states.c +SRCS+= rf_stripelocks.c +SRCS+= rf_strutils.c +SRCS+= rf_threadstuff.c +SRCS+= rf_utils.c +SRCS+= rf_freebsdkintf.c +SRCS+= opt_raid.h vnode_if.h + +RF_AUTOCONFIG?= 1 +RF_DEBUG?= 0 + +opt_raid.h: + echo "#define RAID_AUTOCONFIG ${RF_AUTOCONFIG}" > ${.TARGET} + echo "#define RAID_DEBUG ${RF_DEBUG}" >> ${.TARGET} + +.include diff -ruP raidframe.scottl/rf_bsd.h raidframe/rf_bsd.h --- raidframe.scottl/rf_bsd.h Tue Jan 13 18:22:23 2004 +++ raidframe/rf_bsd.h Tue Jan 13 16:32:04 2004 @@ -126,7 +126,7 @@ } RF_AutoConfig_t; typedef struct RF_ConfigSet_s { - TAILQ_HEAD(,RF_AutoConfig_t) ac_head; + TAILQ_HEAD(,RF_AutoConfig_s) ac_head; TAILQ_ENTRY(RF_ConfigSet_s) cset_link; int rootable; /* Set to 1 if this set can be root */ } RF_ConfigSet_t; diff -ruP raidframe.scottl/rf_freebsdkintf.c raidframe/rf_freebsdkintf.c --- raidframe.scottl/rf_freebsdkintf.c Tue Jan 13 18:22:23 2004 +++ raidframe/rf_freebsdkintf.c Tue Jan 13 18:32:31 2004 @@ -263,7 +263,6 @@ void (*cbFunc) (struct bio *), void *cbArg, int logBytesPerSector, struct proc * b_proc); static struct raid_softc *raidinit(RF_Raid_t *); -static int raid_modevent(module_t, int, void*); static void raidgetdefaultlabel(RF_Raid_t *, struct raid_softc *, struct disk*); static int raidlock(struct raid_softc *); @@ -279,14 +278,23 @@ static void rf_create_auto_sets(void); static int rf_does_it_fit(RF_ConfigSet_t *,RF_AutoConfig_t *); static int rf_reasonable_label(RF_ComponentLabel_t *); +#ifdef not_used static void rf_create_configuration(RF_AutoConfig_t *,RF_Config_t *, RF_Raid_t *); +#endif static int rf_set_autoconfig(RF_Raid_t *, int); static int rf_set_rootpartition(RF_Raid_t *, int); +#ifdef not_used static void rf_cleanup_config_set(RF_ConfigSet_t *); +#endif +#ifdef not_used static int rf_have_enough_components(RF_ConfigSet_t *); +#endif +#ifdef not_used static int rf_auto_config_set(RF_ConfigSet_t *, int *, struct raidctl_softc *); +#endif static void rf_complete_autoconf(void); +static int raidgetunit(struct raidctl_softc *, int); static g_init_t rf_startup; static g_fini_t rf_shutdown; @@ -355,6 +363,71 @@ return; } +static int +rf_destroy(struct gctl_req *req __unused, struct g_class *mp, struct g_geom *gp) +{ + struct g_provider *pp; + struct g_consumer *cp; + + LIST_FOREACH(pp, &gp->provider, provider) { + if (pp->acr != 0 || pp->acw != 0 || pp->ace != 0) + return (EBUSY); + } + + /* + * XXX: All informations have to be destroyed, not only GEOM-related. + */ + LIST_FOREACH(cp, &gp->consumer, consumer) { + g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); + g_detach(cp); + g_destroy_consumer(cp); + } + + g_wither_geom(gp, ENXIO); + + return (0); +} + +static void +rf_component_orphan(struct g_consumer *cp) +{ + struct g_geom *gp; + + g_topology_assert(); + gp = cp->geom; +#if 0 + sc = gp->softc; +#endif + + printf("%s(%s)\n", __func__, gp->name); +} + +static int +rf_component_access(struct g_provider *pp, int dr, int dw, int de) +{ + struct g_geom *gp; + + gp = pp->geom; +#if 0 + sc = gp->softc; +#endif + + printf("%s(%s, %d, %d, %d) (geom=%s)\n", __func__, pp->name, dr, dw, de, + gp->name); + + return (EACCES); +} + +static void +rf_component_start(struct bio *bp) +{ + + printf("%s(%s, %u)\n", __func__, bp->bio_from->provider->name, + bp->bio_cmd); + + g_io_deliver(bp, EOPNOTSUPP); +} + static struct g_geom * rf_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) { @@ -374,14 +447,17 @@ g_topology_assert(); gp = g_new_geomf(mp, "%s.rftaste", pp->name); + gp->start = rf_component_start; gp->spoiled = rf_component_orphan; gp->orphan = rf_component_orphan; + gp->access = rf_component_access; cp = g_new_consumer(gp); g_attach(cp, pp); if (g_access_rel(cp, 1, 0, 0) != 0) { g_detach(cp); g_destroy_consumer(cp); g_destroy_geom(gp); + free(clabel, M_RAIDFRAME); return (NULL); } g_topology_unlock(); @@ -418,6 +494,7 @@ g_detach(cp); g_destroy_consumer(cp); g_destroy_geom(gp); + free(clabel, M_RAIDFRAME); return (NULL); } @@ -1334,13 +1411,15 @@ } bioq_remove(&sc->bio_queue, bp); + /* XXX: This comment should be changed. */ /* Ok, for the bp we have here, bp->b_blkno is relative to the * partition.. Need to make it absolute to the underlying * device.. */ - blocknum = bp->bio_blkno; + blocknum = bp->bio_offset >> DEV_BSHIFT; - rf_printf(3, "Blocks: %ld, %ld\n", (long)bp->bio_blkno, (long)blocknum); + rf_printf(3, "Offset: %jd\n", (intmax_t)bp->bio_offset); + rf_printf(3, "Blocks: %ld\n", (long)blocknum); rf_printf(3, "bp->bio_bcount = %d\n", (int) bp->bio_bcount); rf_printf(3, "bp->bio_resid = %d\n", (int) bp->bio_resid); @@ -1443,11 +1522,12 @@ bp->bio_error = 0; } #endif - raidbp = SOME_GEOM_CLONE_THING(); + raidbp = g_clone_bio(bp); /* * context for raidiodone */ + /* XXX: This is not needed, because bio_parent field is set to this value. */ raidbp->bio_caller1 = bp; raidbp->bio_caller2 = req; @@ -1470,14 +1550,14 @@ if (req->tracerec) { RF_ETIMER_START(req->tracerec->timer); } - InitBP(raidbp, queue->dev, op | bp->bio_cmd, + InitBP(raidbp, (struct g_consumer *)queue->dev, op | bp->bio_cmd, req->sectorOffset, req->numSector, req->buf, KernelWakeupFunc, (void *) req, queue->raidPtr->logBytesPerSector, req->b_proc); if (rf_debugKernelAccess) { - rf_printf(0, "dispatch: bp->bio_blkno = %ld\n", - (long) bp->bio_blkno); + rf_printf(0, "dispatch: bp->bio_offset = %jd\n", + (intmax_t)bp->bio_offset); } queue->numOutstanding++; queue->last_deq_sector = req->sectorOffset; @@ -1493,6 +1573,7 @@ (int) (req->numSector << queue->raidPtr->logBytesPerSector), (int) queue->raidPtr->logBytesPerSector); +#define BIO_STRATEGY(x) BIO_STRATEGY(&raidbp->rf_buf); break; @@ -1592,9 +1673,9 @@ bp->bio_cmd = rw_flag; /* XXX need B_PHYS here too? */ bp->bio_bcount = numSect << logBytesPerSector; bp->bio_error = 0; - bp->bio_dev = dev; + bp->bio_from = cp; bp->bio_data = buf; - bp->bio_blkno = startSect; + bp->bio_offset = startSect << DEV_BSHIFT; bp->bio_resid = bp->bio_bcount; /* XXX is this right!?!?!! */ if (bp->bio_bcount == 0) { panic("bp->bio_bcount is zero in InitBP!!\n"); @@ -1695,7 +1776,7 @@ return (ENOMEM); } - raidread_component_label(disk->dev, clabel); + raidread_component_label(disk, clabel); clabel->mod_counter = mod_counter; clabel->clean = RF_RAID_DIRTY; raidwrite_component_label(disk, clabel); @@ -1724,7 +1805,7 @@ int raidwrite_component_label(RF_Device_t disk, RF_ComponentLabel_t *clabel) { - struct g_consumer *cp + struct g_consumer *cp; int error; cp = (struct g_consumer *)disk; @@ -1773,7 +1854,7 @@ raidPtr->Disks[r][c].dev, clabel); #endif - raidmarkdirty(raidPtr->Disks[r][c], + raidmarkdirty(raidPtr->Disks[r][c].dev, raidPtr->mod_counter); } } @@ -1874,7 +1955,7 @@ raidPtr->Disks[r][c].dev, clabel); if ((final == RF_FINAL_COMPONENT_UPDATE) && (raidPtr->parity_good == RF_RAID_CLEAN)) { - raidmarkclean(raidPtr->Disks[r][c], + raidmarkclean(raidPtr->Disks[r][c].dev, raidPtr->mod_counter); } } @@ -1924,7 +2005,7 @@ clabel); if ((final == RF_FINAL_COMPONENT_UPDATE) && (raidPtr->parity_good == RF_RAID_CLEAN)) { - raidmarkclean(raidPtr->Disks[0][sparecol], + raidmarkclean(raidPtr->Disks[0][sparecol].dev, raidPtr->mod_counter); } } @@ -1938,15 +2019,15 @@ { struct g_consumer *cp; - cp = (struct g_consumer_t *)disk; + cp = (struct g_consumer *)disk; if (cp != NULL) { - g_access_rel(cp, -1, -1, 0); + g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); } else { rf_printf(1, "device was NULL\n"); } -#error "Not done yet" - /* gotta do the geom detach thing */ + g_detach(cp); + g_destroy_consumer(cp); } void @@ -2112,8 +2193,6 @@ RF_AutoConfig_t *ac; RF_ConfigSet_t *cset; - - config_sets = NULL; TAILQ_INIT(&raidctl->cset_head); /* Go through the AutoConfig list, and figure out which components @@ -2132,9 +2211,10 @@ TAILQ_INSERT_TAIL(&raidctl->cset_head, cset, cset_link); cset->rootable = 0; } else { + int ac_claimed = 0; + /* which set does this component fit into? */ TAILQ_FOREACH(cset, &raidctl->cset_head, cset_link) { - ac_claimed = 0; if (rf_does_it_fit(cset, ac)) { /* looks like it matches... */ TAILQ_INSERT_TAIL(&cset->ac_head, ac, @@ -2146,7 +2226,7 @@ if (ac_claimed == 0) { /* didn't find a match above... new set..*/ cset = malloc(sizeof(RF_ConfigSet_t), - M_RAIDFRAME, m_ZERO | M_NOWAIT); + M_RAIDFRAME, M_ZERO | M_NOWAIT); if (cset == NULL) { panic("rf_create_auto_sets: No memory!\n"); } @@ -2157,9 +2237,6 @@ } } } - - - return(config_sets); } static int @@ -2194,7 +2271,7 @@ */ - clabel1 = cset->ac->clabel; + clabel1 = TAILQ_FIRST(&cset->ac_head)->clabel; /* XXX: Correct?! */ clabel2 = ac->clabel; if ((clabel1->version == clabel2->version) && (clabel1->serial_number == clabel2->serial_number) && @@ -2221,12 +2298,12 @@ return(1); } +#ifdef not_used static int rf_have_enough_components(cset) RF_ConfigSet_t *cset; { RF_AutoConfig_t *ac; - RF_AutoConfig_t *auto_config; RF_ComponentLabel_t *clabel; int r,c; int num_rows; @@ -2241,9 +2318,10 @@ /* check to see that we have enough 'live' components of this set. If so, we can configure it if necessary */ - num_rows = cset->ac->clabel->num_rows; - num_cols = cset->ac->clabel->num_columns; - parity_type = cset->ac->clabel->parityConfig; + ac = TAILQ_FIRST(&cset->ac_head); /* XXX: Correct?! */ + num_rows = ac->clabel->num_rows; + num_cols = ac->clabel->num_columns; + parity_type = ac->clabel->parityConfig; /* XXX Check for duplicate components!?!?!? */ @@ -2251,8 +2329,7 @@ mod_counter_found = 0; mod_counter = 0; - ac = cset->ac; - while(ac!=NULL) { + TAILQ_FOREACH(ac, &cset->ac_head, ac_link) { if (mod_counter_found==0) { mod_counter = ac->clabel->mod_counter; mod_counter_found = 1; @@ -2261,17 +2338,14 @@ mod_counter = ac->clabel->mod_counter; } } - ac = ac->next; } num_missing = 0; - auto_config = cset->ac; for(r=0; rac_head, ac_link) { if ((ac->clabel->row == r) && (ac->clabel->column == c) && (ac->clabel->mod_counter == mod_counter)) { @@ -2280,7 +2354,6 @@ ac->devname, r, c); break; } - ac=ac->next; } if (ac==NULL) { /* Didn't find one here! */ @@ -2314,7 +2387,7 @@ } } - clabel = cset->ac->clabel; + clabel = TAILQ_FIRST(&cset->ac_head)->clabel; /* XXX: Correct?! */ if (((clabel->parityConfig == '0') && (num_missing > 0)) || ((clabel->parityConfig == '4') && (num_missing > 1)) || @@ -2327,7 +2400,9 @@ at autoconfiguring this set */ return(1); } +#endif +#ifdef not_used static void rf_create_configuration(ac,config,raidPtr) RF_AutoConfig_t *ac; @@ -2357,13 +2432,14 @@ in reasonable_label() */ strcpy(config->devnames[ac->clabel->row][ac->clabel->column], ac->devname); - ac = ac->next; + ac = TAILQ_NEXT(ac, ac_link); } for(i=0;idebugVars[i][0] = '\0'; } } +#endif static int rf_set_autoconfig(raidPtr, new_value) @@ -2371,7 +2447,7 @@ int new_value; { RF_ComponentLabel_t *clabel; - RF_Device_t *disk; + RF_Device_t disk; int row, column; clabel = malloc(sizeof(RF_ComponentLabel_t), M_RAIDFRAME, @@ -2399,7 +2475,7 @@ int new_value; { RF_ComponentLabel_t *clabel; - RF_Device_t *disk; + RF_Device_t disk; int row, column; clabel = malloc(sizeof(RF_ComponentLabel_t), M_RAIDFRAME, @@ -2421,13 +2497,13 @@ return(new_value); } +#ifdef not_used static void -rf_cleanup_config_set(RF_ConfigSet *cset) +rf_cleanup_config_set(RF_ConfigSet_t *cset) { RF_AutoConfig_t *ac, *next_ac; - RF_AutoConfig_t *next_ac; - ac = TAILQ_HEAD(cset->ac_head); + ac = TAILQ_FIRST(&cset->ac_head); while(ac != NULL) { next_ac = TAILQ_NEXT(ac, ac_link); /* nuke the label */ @@ -2440,7 +2516,7 @@ /* and, finally, nuke the config set */ free(cset, M_RAIDFRAME); } - +#endif void raid_init_component_label(raidPtr, clabel) @@ -2472,6 +2548,7 @@ clabel->config_order = raidPtr->config_order; } +#ifdef not_used static int rf_auto_config_set(cset, unit, ctl) RF_ConfigSet_t *cset; @@ -2505,7 +2582,7 @@ on last time.. */ - raidID = cset->ac->clabel->last_unit; + raidID = TAILQ_FIRST(&cset->ac_head)->clabel->last_unit; if (raidID < 0) { /* let's not wander off into lala land. */ raidID = raidgetunit(ctl, 0); @@ -2532,10 +2609,10 @@ raidPtr->openings = RAIDOUTSTANDING; /* 3. Build the configuration structure */ - rf_create_configuration(cset->ac, config, raidPtr); + rf_create_configuration(TAILQ_FIRST(&cset->ac_head), config, raidPtr); /* 4. Do the configuration */ - retcode = rf_Configure(raidPtr, config, cset->ac); + retcode = rf_Configure(raidPtr, config, TAILQ_FIRST(&cset->ac_head)); if (retcode == 0) { @@ -2550,7 +2627,7 @@ ctl->numraid++; rf_markalldirty(raidPtr); raidPtr->autoconfigure = 1; /* XXX do this here? */ - if (cset->ac->clabel->root_partition==1) { + if (TAILQ_FIRST(&cset->ac_head)->clabel->root_partition==1) { /* everything configured just fine. Make a note that this set is eligible to be root. */ cset->rootable = 1; @@ -2565,6 +2642,7 @@ *unit = raidID; return(retcode); } +#endif void rf_disk_unbusy(desc) @@ -2577,6 +2655,37 @@ bp = (struct bio *)desc->bp; } +/* + * Get the next available unit number from the bitmap. You can also request + * a particular unit number by passing it in the second arg. If it's not + * available, then grab the next free one. Return -1 if none are available. + */ +static int +raidgetunit(struct raidctl_softc *parent_sc, int id) +{ +#if 0 + int i; + + if (id >= RF_MAX_ARRAYS) + return (-1); + + for (i = id; i < RF_MAX_ARRAYS; i++) { + if (parent_sc->sc_raiddevs[i] == NULL) + return (i); + } + + if (id != 0) { + for (i = 0; i < id; i++) { + if (parent_sc->sc_raiddevs[i] == NULL) + return (i); + } + } +#endif + + return (-1); +} + +#ifdef not_used int raid_getcomponentsize(RF_Raid_t *raidPtr, RF_RowCol_t row, RF_RowCol_t col) { @@ -2601,12 +2710,15 @@ return(retcode); } +#endif static void rf_complete_autoconf(void) { rf_create_auto_sets(); +#ifdef not_yet rf_auto_config_set(); +#endif } static struct g_class g_raidframe_class = { @@ -2614,7 +2726,7 @@ .taste = rf_taste, .init = rf_startup, .fini = rf_shutdown, - .destry_geom = rf_destroy, + .destroy_geom = rf_destroy, }; DECLARE_GEOM_CLASS(g_raidframe_class, g_raidframe); @@ -2624,4 +2736,4 @@ * devices have been found (via SI_SUB_DRIVER and interrupt configuration * hook) before we reach here. */ -SYSINIT(raidframe, SI_SUB_RAID, SI_ORDER_LAST, rf_complete_autoconf, NULL); +SYSINIT(raidframe, SI_SUB_RAID, SI_ORDER_ANY, rf_complete_autoconf, NULL); diff -ruP raidframe.scottl/rf_types.h raidframe/rf_types.h --- raidframe.scottl/rf_types.h Tue Jan 13 18:22:23 2004 +++ raidframe/rf_types.h Tue Jan 13 18:28:04 2004 @@ -241,7 +241,7 @@ #if defined(__FreeBSD__) && __FreeBSD_version > 500005 typedef struct bio *RF_Buf_t; -typedef struct rf_device *RF_Device_t; +typedef struct g_consumer *RF_Device_t; #else typedef struct buf *RF_Buf_t; #endif