X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=super0.c;h=d2338a9d2d689a8518d318b7830a992497307390;hp=7025445583e7b313409ade9fee8c6b2e1929ac7c;hb=758d3a8e7d3e0620d68d3b9e72ef0747319c6dac;hpb=8a46fe8487986f96e5313156336c02cc551282c8 diff --git a/super0.c b/super0.c index 70254455..d2338a9d 100644 --- a/super0.c +++ b/super0.c @@ -27,8 +27,9 @@ * Australia */ +#define HAVE_STDINT_H 1 #include "mdadm.h" -#include /* for SHA1 */ +#include "sha1.h" /* * All handling for the 0.90.0 version superblock is in * this file. @@ -98,9 +99,10 @@ static void examine_super0(void *sbv, char *homehost) printf(" UUID : %08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, sb->set_uuid2, sb->set_uuid3); if (homehost) { - unsigned char *hash = SHA1((unsigned char *)homehost, - strlen(homehost), - NULL); + char buf[20]; + void *hash = sha1_buffer(homehost, + strlen(homehost), + buf); if (memcmp(&sb->set_uuid2, hash, 8)==0) printf(" (local to host %s)", homehost); } @@ -189,6 +191,8 @@ static void examine_super0(void *sbv, char *homehost) case 0: case 4: case 5: + case 6: + case 10: printf(" Chunk Size : %dK\n", sb->chunk_size/1024); break; case -1: @@ -227,9 +231,12 @@ static void brief_examine_super0(void *sbv) { mdp_super_t *sb = sbv; char *c=map_num(pers, sb->level); + char devname[20]; + + sprintf(devname, "/dev/md%d", sb->md_minor); printf("ARRAY %s level=%s num-devices=%d UUID=", - get_md_name(sb->md_minor), + devname, c?c:"-unknown-", sb->raid_disks); if (sb->minor_version >= 90) printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, @@ -249,9 +256,10 @@ static void detail_super0(void *sbv, char *homehost) else printf("%08x", sb->set_uuid0); if (homehost) { - unsigned char *hash = SHA1((unsigned char *)homehost, - strlen(homehost), - NULL); + char buf[20]; + void *hash = sha1_buffer(homehost, + strlen(homehost), + buf); if (memcmp(&sb->set_uuid2, hash, 8)==0) printf(" (local to host %s)", homehost); } @@ -273,9 +281,10 @@ static void brief_detail_super0(void *sbv) static int match_home0(void *sbv, char *homehost) { mdp_super_t *sb = sbv; - unsigned char *hash = SHA1((unsigned char *)homehost, - strlen(homehost), - NULL); + char buf[20]; + char *hash = sha1_buffer(homehost, + strlen(homehost), + buf); return (memcmp(&sb->set_uuid2, hash, 8)==0); } @@ -311,6 +320,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv) info->array.ctime = sb->ctime; info->array.utime = sb->utime; info->array.chunk_size = sb->chunk_size; + info->array.state = sb->state; info->component_size = sb->size*2; info->disk.state = sb->this_disk.state; @@ -338,6 +348,7 @@ static void getinfo_super0(struct mdinfo *info, void *sbv) /* 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].state & (1<disks[i].state & (1<= sb->raid_disks && sb->disks[i].number == 0) sb->disks[i].state = 0; } - if (strcmp(update, "force")==0) { + if (strcmp(update, "force-one")==0) { + /* Not enough devices for a working array, so + * bring this one up-to-date. + */ __u32 ehi = sb->events_hi, elo = sb->events_lo; sb->events_hi = (info->events>>32) & 0xFFFFFFFF; sb->events_lo = (info->events) & 0xFFFFFFFF; if (sb->events_hi != ehi || sb->events_lo != elo) rv = 1; + } + if (strcmp(update, "force-array")==0) { + /* degraded array and 'force' requested, so + * maybe need to mark it 'clean' + */ if ((sb->level == 5 || sb->level == 4 || sb->level == 6) && (sb->state & (1 << MD_SB_CLEAN)) == 0) { /* need to force clean */ @@ -424,16 +443,6 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, rv = 1; } } - if (strcmp(update, "newdev") == 0) { - int d = info->disk.number; - memset(&sb->disks[d], 0, sizeof(sb->disks[d])); - sb->disks[d].number = d; - sb->disks[d].major = info->disk.major; - sb->disks[d].minor = info->disk.minor; - sb->disks[d].raid_disk = info->disk.raid_disk; - sb->disks[d].state = info->disk.state; - sb->this_disk = sb->disks[d]; - } if (strcmp(update, "grow") == 0) { sb->raid_disks = info->array.raid_disks; sb->nr_disks = info->array.nr_disks; @@ -462,9 +471,10 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, } if (strcmp(update, "uuid") == 0) { if (!uuid_set && homehost) { - unsigned char *hash = SHA1((unsigned char*)homehost, - strlen(homehost), - NULL); + char buf[20]; + char *hash = sha1_buffer(homehost, + strlen(homehost), + buf); memcpy(info->uuid+2, hash, 8); } sb->set_uuid0 = info->uuid[0]; @@ -484,12 +494,6 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update, return rv; } -static __u64 event_super0(void *sbv) -{ - mdp_super_t *sb = sbv; - return md_event(sb); -} - /* * For verion-0 superblock, the homehost is 'stored' in the * uuid. 8 bytes for a hash of the host leaving 8 bytes @@ -545,9 +549,10 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, if (rfd >= 0) close(rfd); if (homehost) { - unsigned char *hash = SHA1((unsigned char*)homehost, - strlen(homehost), - NULL); + char buf[20]; + char *hash = sha1_buffer(homehost, + strlen(homehost), + buf); memcpy(&sb->set_uuid2, hash, 8); } @@ -613,7 +618,8 @@ static int store_super0(struct supertype *st, int fd, void *sbv) if (super->state & (1<magic) == BITMAP_MAGIC) - write(fd, bm, sizeof(*bm)); + if (write(fd, bm, sizeof(*bm)) != sizeof(*bm)) + return 5; } fsync(fd); @@ -632,7 +638,6 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d } sb->disks[dinfo->number].state &= ~(1<disks[dinfo->number].state |= (1<this_disk = sb->disks[dinfo->number]; sb->sb_csum = calc_sb0_csum(sb); @@ -823,7 +828,10 @@ 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 chunk, int delay, int write_behind, unsigned long long size, int may_change, int major) +static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, + int delay, int write_behind, + unsigned long long size, int may_change, + int major) { /* * The bitmap comes immediately after the superblock and must be 60K in size @@ -834,6 +842,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int unsigned long long bits; unsigned long long max_bits = 60*1024*8; unsigned long long min_chunk; + int chunk = *chunkp; mdp_super_t *sb = sbv; bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES); @@ -859,7 +868,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int bms->daemon_sleep = __cpu_to_le32(delay); bms->sync_size = __cpu_to_le64(size); bms->write_behind = __cpu_to_le32(write_behind); - + *chunkp = chunk; return 1; } @@ -957,7 +966,6 @@ struct superswitch super0 = { .uuid_from_super = uuid_from_super0, .getinfo_super = getinfo_super0, .update_super = update_super0, - .event_super = event_super0, .init_super = init_super0, .add_to_super = add_to_super0, .store_super = store_super0,