X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=super0.c;h=3ae236a82d57b9d8fd7efff4a96b7e5d1d6e3ba8;hb=815c8a7e0b11b69331211b59b880ba50f3ed2b5e;hp=15b3ca2f6ba5069f9146eb63a1fa5ffb58ee58b7;hpb=b42f577a0dbe0b232600478f4a5068b2f63a2684;p=thirdparty%2Fmdadm.git diff --git a/super0.c b/super0.c index 15b3ca2f..3ae236a8 100644 --- a/super0.c +++ b/super0.c @@ -113,7 +113,7 @@ static void examine_super0(struct supertype *st, char *homehost) printf(" Creation Time : %.24s\n", ctime(&atime)); c=map_num(pers, sb->level); printf(" Raid Level : %s\n", c?c:"-unknown-"); - if ((int)sb->level >= 0) { + if ((int)sb->level > 0) { int ddsks=0; printf(" Used Dev Size : %d%s\n", sb->size, human_size((long long)sb->size<<10)); @@ -339,11 +339,12 @@ static void uuid_from_super0(struct supertype *st, int uuid[4]) } } -static void getinfo_super0(struct supertype *st, struct mdinfo *info) +static void getinfo_super0(struct supertype *st, struct mdinfo *info, char *map) { mdp_super_t *sb = st->sb; int working = 0; int i; + int map_disks = info->array.raid_disks; info->array.major_version = sb->major_version; info->array.minor_version = sb->minor_version; @@ -372,6 +373,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info) uuid_from_super0(st, info->uuid); + info->recovery_start = MaxSector; if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) { info->reshape_active = 1; info->reshape_progress = sb->reshape_position; @@ -388,21 +390,37 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info) /* work_disks is calculated rather than read directly */ for (i=0; i < MD_SB_DISKS; i++) if ((sb->disks[i].state & (1<disks[i].raid_disk < info->array.raid_disks) && + (sb->disks[i].raid_disk < (unsigned)info->array.raid_disks) && (sb->disks[i].state & (1<disks[i].state & (1<disks[i].state & (1<array.working_disks = working; } +static struct mdinfo *container_content0(struct supertype *st, char *subarray) +{ + struct mdinfo *info; + + if (subarray) + return NULL; + + info = malloc(sizeof(*info)); + getinfo_super0(st, info, NULL); + return info; +} static int update_super0(struct supertype *st, struct mdinfo *info, char *update, char *devname, int verbose, int uuid_set, char *homehost) { - /* NOTE: for 'assemble' and 'force' we need to return non-zero if any change was made. - * For others, the return value is ignored. + /* NOTE: for 'assemble' and 'force' we need to return non-zero + * if any change was made. For others, the return value is + * ignored. */ int rv = 0; mdp_super_t *sb = st->sb; @@ -418,15 +436,13 @@ static int update_super0(struct supertype *st, struct mdinfo *info, if (verbose >= 0) fprintf (stderr, Name ": adjusting superblock of %s for 2.2/sparc compatability.\n", devname); - } - if (strcmp(update, "super-minor") ==0) { + } else if (strcmp(update, "super-minor") ==0) { sb->md_minor = info->array.md_minor; if (verbose > 0) fprintf(stderr, Name ": updating superblock of %s with minor number %d\n", devname, info->array.md_minor); - } - if (strcmp(update, "summaries") == 0) { - int i; + } else if (strcmp(update, "summaries") == 0) { + unsigned int i; /* set nr_disks, active_disks, working_disks, * failed_disks, spare_disks based on disks[] * array in superblock. @@ -452,8 +468,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->spare_disks++; } else if (i >= sb->raid_disks && sb->disks[i].number == 0) sb->disks[i].state = 0; - } - if (strcmp(update, "force-one")==0) { + } else if (strcmp(update, "force-one")==0) { /* Not enough devices for a working array, so * bring this one up-to-date. */ @@ -463,8 +478,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, if (sb->events_hi != ehi || sb->events_lo != elo) rv = 1; - } - if (strcmp(update, "force-array")==0) { + } else if (strcmp(update, "force-array")==0) { /* degraded array and 'force' requested, so * maybe need to mark it 'clean' */ @@ -474,8 +488,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->state |= (1 << MD_SB_CLEAN); rv = 1; } - } - if (strcmp(update, "assemble")==0) { + } else if (strcmp(update, "assemble")==0) { int d = info->disk.number; int wonly = sb->disks[d].state & (1<disks[d].state & ~mask) | add) - != info->disk.state) { + != (unsigned)info->disk.state) { sb->disks[d].state = info->disk.state | wonly; rv = 1; } - } - if (strcmp(update, "linear-grow-new") == 0) { + if (info->reshape_active && + sb->minor_version > 90 && (sb->reshape_position+1) != 0 && + info->delta_disks >= 0 && + info->reshape_progress < sb->reshape_position) { + sb->reshape_position = info->reshape_progress; + rv = 1; + } + if (info->reshape_active && + sb->minor_version > 90 && (sb->reshape_position+1) != 0 && + info->delta_disks < 0 && + info->reshape_progress > sb->reshape_position) { + sb->reshape_position = info->reshape_progress; + rv = 1; + } + } else if (strcmp(update, "linear-grow-new") == 0) { memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0])); sb->disks[info->disk.number].number = info->disk.number; sb->disks[info->disk.number].major = info->disk.major; @@ -499,8 +525,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->disks[info->disk.number].raid_disk = info->disk.raid_disk; sb->disks[info->disk.number].state = info->disk.state; sb->this_disk = sb->disks[info->disk.number]; - } - if (strcmp(update, "linear-grow-update") == 0) { + } else if (strcmp(update, "linear-grow-update") == 0) { sb->raid_disks = info->array.raid_disks; sb->nr_disks = info->array.nr_disks; sb->active_disks = info->array.active_disks; @@ -511,20 +536,17 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->disks[info->disk.number].minor = info->disk.minor; sb->disks[info->disk.number].raid_disk = info->disk.raid_disk; sb->disks[info->disk.number].state = info->disk.state; - } - if (strcmp(update, "resync") == 0) { + } else if (strcmp(update, "resync") == 0) { /* make sure resync happens */ sb->state &= ~(1<recovery_cp = 0; - } - if (strcmp(update, "homehost") == 0 && + } else if (strcmp(update, "homehost") == 0 && homehost) { uuid_set = 0; update = "uuid"; info->uuid[0] = sb->set_uuid0; info->uuid[1] = sb->set_uuid1; - } - if (strcmp(update, "uuid") == 0) { + } else if (strcmp(update, "uuid") == 0) { if (!uuid_set && homehost) { char buf[20]; char *hash = sha1_buffer(homehost, @@ -541,9 +563,12 @@ static int update_super0(struct supertype *st, struct mdinfo *info, bm = (struct bitmap_super_s*)(sb+1); uuid_from_super0(st, (int*)bm->uuid); } - } - if (strcmp(update, "_reshape_progress")==0) + } else if (strcmp(update, "no-bitmap") == 0) { + sb->state &= ~(1<reshape_position = info->reshape_progress; + else + rv = -1; sb->sb_csum = calc_sb0_csum(sb); return rv; @@ -592,7 +617,7 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info, sb->gvalid_words = 0; /* ignored */ sb->ctime = time(0); sb->level = info->level; - if (size != info->size) + if (size != (unsigned long long)info->size) return 0; sb->size = info->size; sb->nr_disks = info->nr_disks; @@ -725,8 +750,8 @@ static int write_init_super0(struct supertype *st) continue; if (di->fd == -1) continue; - Kill(di->devname, 0, 1, 1); - Kill(di->devname, 0, 1, 1); + while (Kill(di->devname, NULL, 0, 1, 1) == 0) + ; sb->disks[di->disk.number].state &= ~(1<devname); - close(di->fd); - di->fd = -1; } return rv; } @@ -812,9 +835,6 @@ static int load_super0(struct supertype *st, int fd, char *devname) free_super0(st); - if (st->subarray[0]) - return 1; - if (!get_dev_size(fd, devname, &dsize)) return 1; @@ -912,6 +932,7 @@ static struct supertype *match_metadata_desc0(char *arg) if (!st) return st; memset(st, 0, sizeof(*st)); + st->container_dev = NoMdDev; st->ss = &super0; st->info = NULL; st->minor_version = 90; @@ -921,7 +942,11 @@ static struct supertype *match_metadata_desc0(char *arg) while (arg[0] == '0' && arg[1] == '0') arg++; if (strcmp(arg, "0") == 0 || - strcmp(arg, "0.90") == 0 +#ifdef DEFAULT_OLD_METADATA /* ifndef in super1.c */ + strcmp(arg, "default") == 0 || +#endif /* DEFAULT_OLD_METADATA */ + strcmp(arg, "0.90") == 0 || + strcmp(arg, "") == 0 /* no metadata - i.e. non_persistent */ ) return st; @@ -957,7 +982,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp, * size is in sectors, chunk is in bytes !!! */ unsigned long long bits; - unsigned long long max_bits = 60*1024*8; + unsigned long long max_bits = (60*1024 - sizeof(bitmap_super_t))*8; unsigned long long min_chunk; int chunk = *chunkp; mdp_super_t *sb = st->sb; @@ -977,7 +1002,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp, chunk = min_chunk; if (chunk < 64*1024*1024) chunk = 64*1024*1024; - } else if (chunk < min_chunk) + } else if ((unsigned long long)chunk < min_chunk) return 0; /* chunk size too small */ sb->state |= (1< 0) { n = towrite; if (n > 4096) @@ -1066,13 +1091,20 @@ static void free_super0(struct supertype *st) { if (st->sb) free(st->sb); + while (st->info) { + struct devinfo *di = st->info; + st->info = di->next; + if (di->fd >= 0) + close(di->fd); + free(di); + } st->sb = NULL; } #ifndef MDASSEMBLE static int validate_geometry0(struct supertype *st, int level, int layout, int raiddisks, - int chunk, unsigned long long size, + int *chunk, unsigned long long size, char *subdev, unsigned long long *freesize, int verbose) { @@ -1095,6 +1127,9 @@ static int validate_geometry0(struct supertype *st, int level, fprintf(stderr, Name ": 0.90 metadata supports at most 2 terrabytes per device\n"); return 0; } + if (chunk && *chunk == UnSet) + *chunk = DEFAULT_CHUNK; + if (!subdev) return 1; @@ -1135,6 +1170,7 @@ struct superswitch super0 = { .match_home = match_home0, .uuid_from_super = uuid_from_super0, .getinfo_super = getinfo_super0, + .container_content = container_content0, .update_super = update_super0, .init_super = init_super0, .store_super = store_super0,