X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=super0.c;h=27999d994d6fa5347abb19a5a1a4dd0ccd9051f2;hp=873fd95cc3365bb1c63d035f2958eb4608841ee3;hb=d2ca644994d642c31b41242140e1fe819711c8f7;hpb=64557c33917a6f661d091e36ab00065d4107dcee diff --git a/super0.c b/super0.c index 873fd95c..27999d99 100644 --- a/super0.c +++ b/super0.c @@ -85,9 +85,9 @@ void super0_swap_endian(struct mdp_superblock_s *sb) #ifndef MDASSEMBLE -static void examine_super0(struct supertype *st, void *sbv, char *homehost) +static void examine_super0(struct supertype *st, char *homehost) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; time_t atime; int d; char *c; @@ -179,7 +179,9 @@ static void examine_super0(struct supertype *st, void *sbv, char *homehost) printf(" Checksum : %x - correct\n", sb->sb_csum); else printf(" Checksum : %x - expected %lx\n", sb->sb_csum, calc_sb0_csum(sb)); - printf(" Events : %d.%d\n", sb->events_hi, sb->events_lo); + printf(" Events : %llu\n", + ((unsigned long long)sb->events_hi << 32) + + sb->events_lo); printf("\n"); if (sb->level == 5) { c = map_num(r5layout, sb->layout); @@ -231,9 +233,9 @@ static void examine_super0(struct supertype *st, void *sbv, char *homehost) } } -static void brief_examine_super0(struct supertype *st, void *sbv) +static void brief_examine_super0(struct supertype *st) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; char *c=map_num(pers, sb->level); char devname[20]; @@ -250,9 +252,28 @@ static void brief_examine_super0(struct supertype *st, void *sbv) printf("\n"); } -static void detail_super0(struct supertype *st, void *sbv, char *homehost) +static void export_examine_super0(struct supertype *st) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; + + printf("MD_LEVEL=%s\n", map_num(pers, sb->level)); + printf("MD_DEVICES=%d\n", sb->raid_disks); + if (sb->minor_version >= 90) + printf("MD_UUID=%08x:%08x:%08x:%08x\n", + sb->set_uuid0, sb->set_uuid1, + sb->set_uuid2, sb->set_uuid3); + else + printf("MD_UUID=%08x\n", sb->set_uuid0); + printf("MD_UPDATE_TIME=%llu\n", + __le64_to_cpu(sb->ctime) & 0xFFFFFFFFFFULL); + printf("MD_EVENTS=%llu\n", + ((unsigned long long)sb->events_hi << 32) + + sb->events_lo); +} + +static void detail_super0(struct supertype *st, char *homehost) +{ + mdp_super_t *sb = st->sb; printf(" UUID : "); if (sb->minor_version >= 90) printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, @@ -270,9 +291,9 @@ static void detail_super0(struct supertype *st, void *sbv, char *homehost) printf("\n Events : %d.%d\n\n", sb->events_hi, sb->events_lo); } -static void brief_detail_super0(struct supertype *st, void *sbv) +static void brief_detail_super0(struct supertype *st) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; printf(" UUID="); if (sb->minor_version >= 90) printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, @@ -281,9 +302,9 @@ static void brief_detail_super0(struct supertype *st, void *sbv) printf("%08x", sb->set_uuid0); } -static void export_super0(struct supertype *st, void *sbv) +static void export_detail_super0(struct supertype *st) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; printf("MD_UUID="); if (sb->minor_version >= 90) printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, @@ -294,9 +315,9 @@ static void export_super0(struct supertype *st, void *sbv) } #endif -static int match_home0(struct supertype *st, void *sbv, char *homehost) +static int match_home0(struct supertype *st, char *homehost) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; char buf[20]; char *hash = sha1_buffer(homehost, strlen(homehost), @@ -305,9 +326,9 @@ static int match_home0(struct supertype *st, void *sbv, char *homehost) return (memcmp(&sb->set_uuid2, hash, 8)==0); } -static void uuid_from_super0(struct supertype *st, int uuid[4], void * sbv) +static void uuid_from_super0(struct supertype *st, int uuid[4]) { - mdp_super_t *super = sbv; + mdp_super_t *super = st->sb; uuid[0] = super->set_uuid0; if (super->minor_version >= 90) { uuid[1] = super->set_uuid1; @@ -320,9 +341,9 @@ static void uuid_from_super0(struct supertype *st, int uuid[4], void * sbv) } } -static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv) +static void getinfo_super0(struct supertype *st, struct mdinfo *info) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; int working = 0; int i; @@ -348,7 +369,9 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv) info->events = md_event(sb); info->data_offset = 0; - uuid_from_super0(st, info->uuid, sbv); + sprintf(info->text_version, "0.%d", sb->minor_version); + + uuid_from_super0(st, info->uuid); if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) { info->reshape_active = 1; @@ -373,7 +396,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv) static int update_super0(struct supertype *st, struct mdinfo *info, - void *sbv, char *update, + char *update, char *devname, int verbose, int uuid_set, char *homehost) { @@ -381,7 +404,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, * For others, the return value is ignored. */ int rv = 0; - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; if (strcmp(update, "sparc2.2")==0 ) { /* 2.2 sparc put the events in the wrong place * So we copy the tail of the superblock @@ -508,7 +531,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, if (sb->state & (1<uuid, sbv); + uuid_from_super0(st, (int*)bm->uuid); } } if (strcmp(update, "_reshape_progress")==0) @@ -527,7 +550,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info, */ -static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, +static int init_super0(struct supertype *st, mdu_array_info_t *info, unsigned long long size, char *ignored_name, char *homehost, int *uuid) { @@ -538,7 +561,6 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, st->sb = sb; if (info->major_version == -1) { /* zeroing the superblock */ - *sbp = sb; return 0; } @@ -600,28 +622,48 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, sb->layout = info->layout; sb->chunk_size = info->chunk_size; - *sbp = sb; return 1; } +struct devinfo { + int fd; + char *devname; + mdu_disk_info_t disk; + struct devinfo *next; +}; /* Add a device to the superblock being created */ -static void add_to_super0(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo) +static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo, + int fd, char *devname) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; mdp_disk_t *dk = &sb->disks[dinfo->number]; + struct devinfo *di, **dip; dk->number = dinfo->number; dk->major = dinfo->major; dk->minor = dinfo->minor; dk->raid_disk = dinfo->raid_disk; dk->state = dinfo->state; + + sb->this_disk = sb->disks[dinfo->number]; + sb->sb_csum = calc_sb0_csum(sb); + + dip = (struct devinfo **)&st->info; + while (*dip) + dip = &(*dip)->next; + di = malloc(sizeof(struct devinfo)); + di->fd = fd; + di->devname = devname; + di->disk = *dinfo; + di->next = NULL; + *dip = di; } -static int store_super0(struct supertype *st, int fd, void *sbv) +static int store_super0(struct supertype *st, int fd) { unsigned long long dsize; unsigned long long offset; - mdp_super_t *super = sbv; + mdp_super_t *super = st->sb; if (!get_dev_size(fd, NULL, &dsize)) return 1; @@ -650,31 +692,41 @@ static int store_super0(struct supertype *st, int fd, void *sbv) return 0; } -static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo, char *devname) +#ifndef MDASSEMBLE +static int write_init_super0(struct supertype *st) { - mdp_super_t *sb = sbv; - int fd = open(devname, O_RDWR|O_EXCL); - int rv; + mdp_super_t *sb = st->sb; + int rv = 0; + struct devinfo *di; - if (fd < 0) { - fprintf(stderr, Name ": Failed to open %s to write superblock\n", devname); - return -1; - } + for (di = st->info ; di && ! rv ; di = di->next) { - sb->disks[dinfo->number].state &= ~(1<disk.state == 1) + continue; + if (di->fd == -1) + continue; + Kill(di->devname, 0, 1, 1); + Kill(di->devname, 0, 1, 1); - sb->this_disk = sb->disks[dinfo->number]; - sb->sb_csum = calc_sb0_csum(sb); - rv = store_super0(st, fd, sb); + sb->disks[di->disk.number].state &= ~(1<state & (1<ss->write_bitmap(st, fd, sbv); + sb->this_disk = sb->disks[di->disk.number]; + sb->sb_csum = calc_sb0_csum(sb); + rv = store_super0(st, di->fd); - close(fd); - if (rv) - fprintf(stderr, Name ": failed to write superblock to %s\n", devname); + if (rv == 0 && (sb->state & (1<ss->write_bitmap(st, di->fd); + + if (rv) + fprintf(stderr, + Name ": failed to write superblock to %s\n", + di->devname); + close(di->fd); + di->fd = -1; + } return rv; } +#endif static int compare_super0(struct supertype *st, struct supertype *tst) { @@ -698,8 +750,8 @@ static int compare_super0(struct supertype *st, struct supertype *tst) return 0; } - uuid_from_super0(NULL, uuid1, first); - uuid_from_super0(NULL, uuid2, second); + uuid_from_super0(st, uuid1); + uuid_from_super0(tst, uuid2); if (!same_uuid(uuid1, uuid2, 0)) return 2; if (first->major_version != second->major_version || @@ -716,7 +768,9 @@ static int compare_super0(struct supertype *st, struct supertype *tst) } -static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) +static void free_super0(struct supertype *st); + +static int load_super0(struct supertype *st, int fd, char *devname) { /* try to read in the superblock * Return: @@ -730,6 +784,11 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) int uuid[4]; struct bitmap_super_s *bsb; + free_super0(st); + + if (st->subarray[0]) + return 1; + if (!get_dev_size(fd, devname, &dsize)) return 1; @@ -783,11 +842,12 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) return 2; } st->sb = super; - *sbp = super; + if (st->ss == NULL) { st->ss = &super0; - st->minor_version = 90; + st->minor_version = super->minor_version; st->max_devs = MD_SB_DISKS; + st->info = NULL; } /* Now check on the bitmap superblock */ @@ -801,7 +861,7 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) != sizeof(struct bitmap_super_s)) goto no_bitmap; - uuid_from_super0(st, uuid, super); + uuid_from_super0(st, uuid); bsb = (struct bitmap_super_s *)(super+1); if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC || memcmp(bsb->uuid, uuid, 16) != 0) @@ -819,18 +879,26 @@ static struct supertype *match_metadata_desc0(char *arg) struct supertype *st = malloc(sizeof(*st)); if (!st) return st; + memset(st, 0, sizeof(*st)); st->ss = &super0; + st->info = NULL; st->minor_version = 90; st->max_devs = MD_SB_DISKS; st->sb = NULL; if (strcmp(arg, "0") == 0 || strcmp(arg, "0.90") == 0 || - strcmp(arg, "default") == 0 + strcmp(arg, "default") == 0 || + strcmp(arg, "") == 0 /* no metadata */ ) return st; + st->minor_version = 91; /* reshape in progress */ + if (strcmp(arg, "0.91") == 0) /* For dup_super support */ + return st; + st->minor_version = 9; /* flag for 'byte-swapped' */ - if (strcmp(arg, "0.swap")==0) + if (strcmp(arg, "0.swap")==0 || + strcmp(arg, "0.9") == 0) /* For dup_super support */ return st; free(st); @@ -844,7 +912,7 @@ static __u64 avail_size0(struct supertype *st, __u64 devsize) return MD_NEW_SIZE_SECTORS(devsize); } -static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, +static int add_internal_bitmap0(struct supertype *st, int *chunkp, int delay, int write_behind, unsigned long long size, int may_change, int major) @@ -859,7 +927,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, unsigned long long max_bits = 60*1024*8; unsigned long long min_chunk; int chunk = *chunkp; - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES); @@ -879,7 +947,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, memset(bms, 0, sizeof(*bms)); bms->magic = __cpu_to_le32(BITMAP_MAGIC); bms->version = __cpu_to_le32(major); - uuid_from_super0(st, (int*)bms->uuid, sb); + uuid_from_super0(st, (int*)bms->uuid); bms->chunksize = __cpu_to_le32(chunk); bms->daemon_sleep = __cpu_to_le32(delay); bms->sync_size = __cpu_to_le64(size); @@ -889,7 +957,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, } -void locate_bitmap0(struct supertype *st, int fd, void *sbv) +void locate_bitmap0(struct supertype *st, int fd) { unsigned long long dsize; unsigned long long offset; @@ -909,11 +977,11 @@ void locate_bitmap0(struct supertype *st, int fd, void *sbv) lseek64(fd, offset, 0); } -int write_bitmap0(struct supertype *st, int fd, void *sbv) +int write_bitmap0(struct supertype *st, int fd) { unsigned long long dsize; unsigned long long offset; - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; int rv = 0; @@ -957,19 +1025,59 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv) return rv; } -static void free_super0(struct supertype *st, void *super) +static void free_super0(struct supertype *st) { - if (super) - free(super); + if (st->sb) + free(st->sb); + st->sb = NULL; +} + +static int validate_geometry0(struct supertype *st, int level, + int layout, int raiddisks, + int chunk, unsigned long long size, + char *subdev, unsigned long long *freesize) +{ + unsigned long long ldsize; + int fd; + + if (level == LEVEL_CONTAINER) + return 0; + if (raiddisks > MD_SB_DISKS) + return 0; + if (size > (0x7fffffffULL<<10)) + return 0; + if (!subdev) + return 1; + + fd = open(subdev, O_RDONLY|O_EXCL, 0); + if (fd < 0) { + fprintf(stderr, Name ": Cannot open %s: %s\n", + subdev, strerror(errno)); + return 0; + } + if (!get_dev_size(fd, subdev, &ldsize)) { + close(fd); + return 0; + } + close(fd); + + if (ldsize < MD_RESERVED_SECTORS * 512) + return 0; + if (size > (0x7fffffffULL<<10)) + return 0; + *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9); + return 1; } struct superswitch super0 = { #ifndef MDASSEMBLE .examine_super = examine_super0, .brief_examine_super = brief_examine_super0, + .export_examine_super = export_examine_super0, .detail_super = detail_super0, .brief_detail_super = brief_detail_super0, - .export_super = export_super0, + .export_detail_super = export_detail_super0, + .write_init_super = write_init_super0, #endif .match_home = match_home0, .uuid_from_super = uuid_from_super0, @@ -978,7 +1086,6 @@ struct superswitch super0 = { .init_super = init_super0, .add_to_super = add_to_super0, .store_super = store_super0, - .write_init_super = write_init_super0, .compare_super = compare_super0, .load_super = load_super0, .match_metadata_desc = match_metadata_desc0, @@ -987,6 +1094,5 @@ struct superswitch super0 = { .locate_bitmap = locate_bitmap0, .write_bitmap = write_bitmap0, .free_super = free_super0, - .major = 0, - .swapuuid = 0, + .validate_geometry = validate_geometry0, };