// used by diskmap_initialize() static int dm_layout_g1_compute_blksinband(struct dm_disk_if *d, struct dm_layout_g1_band *b) { struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout; int blksinband; int cylcnt = b->endcyl - b->startcyl + 1; blksinband = cylcnt * b->blkspertrack * d->dm_surfaces; blksinband -= b->deadspace; switch(l->sparescheme) { case TRACK_SPARING: blksinband -= b->sparecnt * b->blkspertrack; break; case SECTPERTRACK_SPARING: blksinband -= b->sparecnt * cylcnt * d->dm_surfaces; break; case SECTATEND_SPARING: blksinband -= b->numslips; break; case SECTSPERZONE_SPARING: blksinband -= b->sparecnt; break; case SECTSPERZONE_SPARING_SLIPTOEND: blksinband -= b->sparecnt + b->numslips; break; default: if ((issectpercyl(l)) && (!(issliptoend(l)))) { blksinband -= b->sparecnt * cylcnt; } else if ((issectpercyl(l)) && (issliptoend(l))) { blksinband -= (b->sparecnt * cylcnt) + b->numslips; } else if (l->sparescheme == SECTPERRANGE_SPARING) { blksinband -= b->sparecnt * (cylcnt / l->rangesize); } else { ddbg_assert3(0, ("Unknown sparing scheme %d", l->sparescheme)); } break; } return blksinband; }
/* instantiate all the elements of <l> as <name> */ int lp_inst_list(struct lp_inst *i) { int c; /* unparse_block(spec, outputfile); */ for(c = 0; c < i->l->values_len; c++) { if(!i->l->values[c]) continue; ddbg_assert3(i->l->values[c]->t == S, ("bad type for component %s", i->l->values[c]->v.s)); lp_instantiate(i->l->values[c]->v.s, i->name); } return 0; }
static void dm_layout_g1_initialize(struct dm_disk_if *d) { int i; struct dm_layout_g1 *l = (struct dm_layout_g1 *)d->layout; ddbg_assert((l->mapping >= 0) && (l->mapping <= LAYOUT_MAX)); for (i = 0; i < l->bands_len; i++) { struct dm_layout_g1_band *b = &l->bands[i]; ddbg_assert3((l->sparescheme != TRACK_SPARING) || ((b->numslips + b->numdefects) <= b->sparecnt), ("Defects and slips outnumber the available spares: %d < %d + %d\n", b->sparecnt, b->numdefects, b->numslips)); b->blksinband = dm_layout_g1_compute_blksinband(d, b); } }
/* instantiate <targ> as <name> */ int *lp_instantiate(char *targ, char *name) { char *nametmp; struct lp_block *spec; int *obj; /* unparse_block(b, outputfile); */ spec = lp_lookup_spec(name); ddbg_assert3(spec != 0, ("no such type %s.\n", name)); // this is a bit of a hack; we swap the name of the component // being instantiated with the name of the module that's being // instantiated so that the loader function sees the target // name nametmp = spec->name; spec->name = targ; // fprintf(stderr, "*** Instantiating %s as %s\n", targ, name); obj = lp_override_inst(spec, targ, lp_modules[spec->type]->fn, overrides, overrides_len); // swap the name back spec->name = nametmp; if(!obj) { return 0; } if(lp_modules[spec->type]->callback) { lp_modules[spec->type]->callback(lp_modules[spec->type]->ctx, obj); } return obj; }
static int layout_g2_loadmap(struct dm_layout_g2 *l) { FILE *fd; char junk[1024]; char countstr[16]; char *mapfile; int extentguess; int extents_ct = 0; struct dm_pbn pbn; int64_t lbn; int c,h,s,count; int lastc, lasth; int cyls, heads; int i, j; // index [cyl][head], number of extents for that track int **track_ext_counts; struct dm_layout_g2_node *curr; struct dm_layout_g2_node *track_extents; struct dm_pbn *currdefect; mapfile = lp_search_path(lp_cwd, l->mapfile); fd = fopen(mapfile, "r"); ddbg_assert3(fd != 0, ("failed to open layout mappings file %s", l->mapfile)); // ignore first 2 lines fgets(junk, sizeof(junk), fd); fgets(junk, sizeof(junk), fd); if(fscanf(fd, "%d cylinders, %*d rot, %d heads\n", &cyls, &heads) != 2) { ddbg_assert2(0, "*** error: layout_g2_loadmap: need <cyls> ... <heads>\n"); } // printf("*** layout_g2: %s %s\n", vendor, model); // printf("*** layout_g2: %d %d\n", cyls, heads); extentguess = cyls * heads * 2; // 0t tracks extentguess += extentguess/4; // if there are a lot of defects l->ltop_map = calloc(extentguess, sizeof(struct dm_layout_g2_node)); curr = &l->ltop_map[0]; l->ptol_map = calloc(cyls, sizeof(struct dm_layout_g2_cyl)); for(i = 0; i < cyls; i++) { l->ptol_map[i].surfaces = calloc(heads, sizeof(struct dm_layout_g2_surf)); } track_ext_counts = calloc(cyls, sizeof(int *)); for(i = 0; i < cyls; i++) { track_ext_counts[i] = calloc(heads, sizeof(int)); } curr = &l->ltop_map[0]; // ltop map while(fscanf(fd, "lbn %d --> cyl %d, head %d, sect %d, %s %d\n", &curr->lbn, &curr->loc.cyl, &curr->loc.head, &curr->loc.sector, countstr, &curr->len) == 6) { if(!strcmp(countstr, "seqcnt")) { curr->len++; } track_ext_counts[curr->loc.cyl][curr->loc.head]++; curr++; extents_ct++; l->ltop_map_len++; } // copy the ltop map and sort it by track track_extents = calloc(extents_ct, sizeof(struct dm_layout_g2_node)); memcpy(track_extents, l->ltop_map, extents_ct * sizeof(struct dm_layout_g2_node)); qsort(track_extents, extents_ct, sizeof(struct dm_layout_g2_node), trackcmp); // ptol map curr = &track_extents[0]; for(i = 0; i < cyls; i++) { for(j = 0; j < heads; j++) { int k; int extents_len = track_ext_counts[i][j]; l->ptol_map[i].surfaces[j].extents = calloc(extents_len, sizeof(struct dm_layout_g2_node)); l->ptol_map[i].surfaces[j].extents_len = extents_len; for(k = 0; k < extents_len; k++) { l->ptol_map[i].surfaces[j].extents[k] = *curr; curr++; } } } // free the extra extent list free(track_extents); // ddbg_assert2(extents_ct > (cyls * heads), "EOF on layout mappings file??"); // l->extents_len = extents_ct; // populate the defect list defects = calloc(extents_ct >> 3, sizeof(struct dm_pbn)); currdefect = &defects[0]; while(fscanf(fd, "Defect at cyl %d, head %d, sect %d\n", &currdefect->cyl, &currdefect->head, &currdefect->sector) == 3) { currdefect++; defects_len++; } fclose(fd); return 0; }
void dm_mech_g1_read_extracted_seek_curve (char *filename, int *cntptr, int **distsptr, dm_time_t **timesptr) { int rv, mat; int lineflag = 1; int count = 0, buflen = 128; int *dists; dm_time_t *times; FILE *seekfile = NULL; char linebuf[1024]; char *pathname = lp_search_path(lp_cwd, filename); if(pathname) { seekfile = fopen(pathname, "r"); } else { ddbg_assert2(0, "Seek file not found in path!"); } ddbg_assert3(seekfile != 0, ("fopen seekfile (%s) failed: %s", filename, strerror(errno))); rv = (fgets(linebuf, sizeof(linebuf), seekfile) != 0); mat = sscanf(linebuf, "Seek distances measured: %d\n", &count); if(mat == 1) { buflen = count; lineflag = 0; } dists = calloc(buflen, sizeof(*dists)); times = calloc(buflen, sizeof(*times)); do { double time, stdev; int dist; if(!lineflag) { rv = (fgets(linebuf, sizeof(linebuf), seekfile) != 0); } else { lineflag = 0; } if(rv) { mat = sscanf(linebuf, "%d, %lf, %lf\n", &dist, &time, &stdev); if(mat == 2 || mat == 3) { if(count >= buflen-1) { buflen *= 2; dists = realloc(dists, buflen * sizeof(*dists)); times = realloc(times, buflen * sizeof(*times)); } dists[count] = dist; times[count] = dm_time_dtoi(time); count++; } else { fprintf(stderr, "*** bogus line in seek curve (%s:%d): %s\n", __FILE__, __LINE__, linebuf); } } } while(rv); fclose(seekfile); *cntptr = count; *distsptr = dists; *timesptr = times; }