X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;ds=sidebyside;f=super0.c;h=71dc39ce4a0dec2ccbb18c0d67ad19e09d636fca;hb=e4965ef8461b3d0db6e94939f07d814d819f86c2;hp=0396c2cd81b4e26074de176c00444d1f818e45c9;hpb=eb6dae98500dd087548b593c9b7e3db7b3cff9b2;p=thirdparty%2Fmdadm.git diff --git a/super0.c b/super0.c index 0396c2cd..71dc39ce 100644 --- a/super0.c +++ b/super0.c @@ -38,7 +38,7 @@ * - initialising a new superblock * - printing the superblock for --examine * - printing part of the superblock for --detail - * .. other stuff + * .. other stuff */ @@ -56,7 +56,7 @@ static unsigned long calc_sb0_csum(mdp_super_t *super) void super0_swap_endian(struct mdp_superblock_s *sb) { /* as super0 superblocks are host-endian, it is sometimes - * useful to be able to swap the endianness + * useful to be able to swap the endianness * as (almost) everything is u32's we byte-swap every 4byte * number. * We then also have to swap the events_hi and events_lo @@ -85,9 +85,9 @@ void super0_swap_endian(struct mdp_superblock_s *sb) #ifndef MDASSEMBLE -static void examine_super0(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,17 +179,18 @@ static void examine_super0(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); printf(" Layout : %s\n", c?c:"-unknown-"); } if (sb->level == 10) { - printf(" Layout : near=%d, %s=%d\n", - sb->layout&255, - (sb->layout&0x10000)?"offset":"far", - (sb->layout>>8)&255); + printf(" Layout :"); + print_r10_layout(sb->layout); + printf("\n"); } switch(sb->level) { case 0: @@ -231,9 +232,9 @@ static void examine_super0(void *sbv, char *homehost) } } -static void brief_examine_super0(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 +251,28 @@ static void brief_examine_super0(void *sbv) printf("\n"); } -static void detail_super0(void *sbv, char *homehost) +static void export_examine_super0(struct supertype *st) +{ + 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 = 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, @@ -270,9 +290,9 @@ static void detail_super0(void *sbv, char *homehost) printf("\n Events : %d.%d\n\n", sb->events_hi, sb->events_lo); } -static void brief_detail_super0(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 +301,9 @@ static void brief_detail_super0(void *sbv) printf("%08x", sb->set_uuid0); } -static void export_super0(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 +314,9 @@ static void export_super0(void *sbv) } #endif -static int match_home0(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 +325,9 @@ static int match_home0(void *sbv, char *homehost) return (memcmp(&sb->set_uuid2, hash, 8)==0); } -static void uuid_from_super0(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 +340,9 @@ static void uuid_from_super0(int uuid[4], void * sbv) } } -static void getinfo_super0(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 +368,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv) info->events = md_event(sb); info->data_offset = 0; - uuid_from_super0(info->uuid, sbv); + uuid_from_super0(st, info->uuid); if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) { info->reshape_active = 1; @@ -372,7 +392,8 @@ static void getinfo_super0(struct mdinfo *info, void *sbv) } -static int update_super0(struct mdinfo *info, void *sbv, char *update, +static int update_super0(struct supertype *st, struct mdinfo *info, + char *update, char *devname, int verbose, int uuid_set, char *homehost) { @@ -380,7 +401,7 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, * 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 @@ -403,14 +424,14 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, if (strcmp(update, "summaries") == 0) { int i; /* set nr_disks, active_disks, working_disks, - * failed_disks, spare_disks based on disks[] + * failed_disks, spare_disks based on disks[] * array in superblock. * Also make sure extra slots aren't 'failed' */ sb->nr_disks = sb->active_disks = sb->working_disks = sb->failed_disks = sb->spare_disks = 0; - for (i=0; i < MD_SB_DISKS ; i++) + for (i=0; i < MD_SB_DISKS ; i++) if (sb->disks[i].major || sb->disks[i].minor) { int state = sb->disks[i].state; @@ -507,7 +528,7 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, if (sb->state & (1<uuid, sbv); + uuid_from_super0(st, (int*)bm->uuid); } } if (strcmp(update, "_reshape_progress")==0) @@ -526,7 +547,7 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, */ -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) { @@ -534,9 +555,9 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, int spares; memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t)); + st->sb = sb; if (info->major_version == -1) { /* zeroing the superblock */ - *sbp = sb; return 0; } @@ -598,14 +619,13 @@ 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; } /* Add a device to the superblock being created */ -static void add_to_super0(void *sbv, mdu_disk_info_t *dinfo) +static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; mdp_disk_t *dk = &sb->disks[dinfo->number]; dk->number = dinfo->number; @@ -615,11 +635,11 @@ static void add_to_super0(void *sbv, mdu_disk_info_t *dinfo) dk->state = dinfo->state; } -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; @@ -648,9 +668,10 @@ 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) +static int write_init_super0(struct supertype *st, + mdu_disk_info_t *dinfo, char *devname) { - mdp_super_t *sb = sbv; + mdp_super_t *sb = st->sb; int fd = open(devname, O_RDWR|O_EXCL); int rv; @@ -663,10 +684,10 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d sb->this_disk = sb->disks[dinfo->number]; sb->sb_csum = calc_sb0_csum(sb); - rv = store_super0(st, fd, sb); + rv = store_super0(st, fd); if (rv == 0 && (sb->state & (1<ss->write_bitmap(st, fd, sbv); + rv = st->ss->write_bitmap(st, fd); close(fd); if (rv) @@ -674,7 +695,7 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d return rv; } -static int compare_super0(void **firstp, void *secondv) +static int compare_super0(struct supertype *st, struct supertype *tst) { /* * return: @@ -683,21 +704,21 @@ static int compare_super0(void **firstp, void *secondv) * 2 wrong uuid * 3 wrong other info */ - mdp_super_t *first = *firstp; - mdp_super_t *second = secondv; - + mdp_super_t *first = st->sb; + mdp_super_t *second = tst->sb; int uuid1[4], uuid2[4]; + if (second->md_magic != MD_SB_MAGIC) return 1; if (!first) { first = malloc(MD_SB_BYTES + sizeof(struct bitmap_super_s)); memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s)); - *firstp = first; + st->sb = first; return 0; } - uuid_from_super0(uuid1, first); - uuid_from_super0(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 || @@ -714,7 +735,9 @@ static int compare_super0(void **firstp, void *secondv) } -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: @@ -727,7 +750,9 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) mdp_super_t *super; int uuid[4]; struct bitmap_super_s *bsb; - + + free_super0(st); + if (!get_dev_size(fd, devname, &dsize)) return 1; @@ -780,10 +805,11 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) free(super); return 2; } - *sbp = super; + st->sb = super; + if (st->ss == NULL) { st->ss = &super0; - st->minor_version = 90; + st->minor_version = super->minor_version; st->max_devs = MD_SB_DISKS; } @@ -798,7 +824,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(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,14 +845,21 @@ static struct supertype *match_metadata_desc0(char *arg) st->ss = &super0; 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); @@ -840,7 +873,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) @@ -855,7 +888,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); @@ -875,7 +908,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((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); @@ -885,7 +918,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; @@ -905,12 +938,12 @@ 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; int towrite, n; @@ -938,7 +971,7 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv) memset(buf, 0xff, sizeof(buf)); while (towrite > 0) { n = towrite; - if (n > sizeof(buf)) + if (n > sizeof(buf)) n = sizeof(buf); n = write(fd, buf, n); if (n > 0) @@ -953,13 +986,21 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv) return rv; } +static void free_super0(struct supertype *st) +{ + if (st->sb) + free(st->sb); + st->sb = NULL; +} + 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, #endif .match_home = match_home0, .uuid_from_super = uuid_from_super0, @@ -976,6 +1017,7 @@ struct superswitch super0 = { .add_internal_bitmap = add_internal_bitmap0, .locate_bitmap = locate_bitmap0, .write_bitmap = write_bitmap0, + .free_super = free_super0, .major = 0, .swapuuid = 0, };