]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Fix compare_super to take supertype instead of a superblock.
[thirdparty/mdadm.git] / super1.c
index 52783e7766cf227ea26e99b85db2df59a34753ad..9bf5912a752fc18b789abb332e4c19fdd6e1d6ad 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -142,7 +142,7 @@ static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
 }
 
 #ifndef MDASSEMBLE
-static void examine_super1(void *sbv, char *homehost)
+static void examine_super1(struct supertype *st, void *sbv, char *homehost)
 {
        struct mdp_superblock_1 *sb = sbv;
        time_t atime;
@@ -182,7 +182,7 @@ static void examine_super1(void *sbv, char *homehost)
        printf("     Raid Level : %s\n", c?c:"-unknown-");
        printf("   Raid Devices : %d\n", __le32_to_cpu(sb->raid_disks));
        printf("\n");
-       printf("  Used Dev Size : %llu%s\n",
+       printf(" Avail Dev Size : %llu%s\n",
               (unsigned long long)__le64_to_cpu(sb->data_size),
               human_size(__le64_to_cpu(sb->data_size)<<9));
        if (__le32_to_cpu(sb->level) >= 0) {
@@ -202,7 +202,7 @@ static void examine_super1(void *sbv, char *homehost)
                               ddsks*(unsigned long long)__le64_to_cpu(sb->size),
                               human_size(ddsks*__le64_to_cpu(sb->size)<<9));
                if (sb->size != sb->data_size)
-                       printf("      Used Size : %llu%s\n",
+                       printf("  Used Dev Size : %llu%s\n",
                               (unsigned long long)__le64_to_cpu(sb->size),
                               human_size(__le64_to_cpu(sb->size)<<9));
        }
@@ -341,7 +341,7 @@ static void examine_super1(void *sbv, char *homehost)
 }
 
 
-static void brief_examine_super1(void *sbv)
+static void brief_examine_super1(struct supertype *st, void *sbv)
 {
        struct mdp_superblock_1 *sb = sbv;
        int i;
@@ -375,7 +375,7 @@ static void brief_examine_super1(void *sbv)
        printf("\n");
 }
 
-static void detail_super1(void *sbv, char *homehost)
+static void detail_super1(struct supertype *st, void *sbv, char *homehost)
 {
        struct mdp_superblock_1 *sb = sbv;
        int i;
@@ -394,7 +394,7 @@ static void detail_super1(void *sbv, char *homehost)
        printf("\n         Events : %llu\n\n", (unsigned long long)__le64_to_cpu(sb->events));
 }
 
-static void brief_detail_super1(void *sbv)
+static void brief_detail_super1(struct supertype *st, void *sbv)
 {
        struct mdp_superblock_1 *sb = sbv;
        int i;
@@ -408,7 +408,7 @@ static void brief_detail_super1(void *sbv)
        }
 }
 
-static void export_super1(void *sbv)
+static void export_super1(struct supertype *st, void *sbv)
 {
        struct mdp_superblock_1 *sb = sbv;
        int i;
@@ -432,7 +432,7 @@ static void export_super1(void *sbv)
 
 #endif
 
-static int match_home1(void *sbv, char *homehost)
+static int match_home1(struct supertype *st, void *sbv, char *homehost)
 {
        struct mdp_superblock_1 *sb = sbv;
        int l = homehost ? strlen(homehost) : 0;
@@ -442,7 +442,7 @@ static int match_home1(void *sbv, char *homehost)
                strncmp(sb->set_name, homehost, l) == 0);
 }
 
-static void uuid_from_super1(int uuid[4], void * sbv)
+static void uuid_from_super1(struct supertype *st, int uuid[4], void * sbv)
 {
        struct mdp_superblock_1 *super = sbv;
        char *cuuid = (char*)uuid;
@@ -451,7 +451,7 @@ static void uuid_from_super1(int uuid[4], void * sbv)
                cuuid[i] = super->set_uuid[i];
 }
 
-static void getinfo_super1(struct mdinfo *info, void *sbv)
+static void getinfo_super1(struct supertype *st, struct mdinfo *info, void *sbv)
 {
        struct mdp_superblock_1 *sb = sbv;
        int working = 0;
@@ -522,7 +522,8 @@ static void getinfo_super1(struct mdinfo *info, void *sbv)
        info->array.working_disks = working;
 }
 
-static int update_super1(struct mdinfo *info, void *sbv, char *update,
+static int update_super1(struct supertype *st, struct mdinfo *info,
+                        void *sbv, char *update,
                         char *devname, int verbose,
                         int uuid_set, char *homehost)
 {
@@ -660,6 +661,7 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info,
        char defname[10];
        memset(sb, 0, 1024);
 
+       st->sb = sb;
        if (info->major_version == -1) {
                /* zeroing superblock */
                *sbp = sb;
@@ -734,7 +736,7 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info,
 }
 
 /* Add a device to the superblock being created */
-static void add_to_super1(void *sbv, mdu_disk_info_t *dk)
+static void add_to_super1(struct supertype *st, void *sbv, mdu_disk_info_t *dk)
 {
        struct mdp_superblock_1 *sb = sbv;
        __u16 *rp = sb->dev_roles + dk->number;
@@ -946,7 +948,7 @@ static int write_init_super1(struct supertype *st, void *sbv,
        return rv;
 }
 
-static int compare_super1(void **firstp, void *secondv)
+static int compare_super1(struct supertype *st, struct supertype *tst)
 {
        /*
         * return:
@@ -955,8 +957,8 @@ static int compare_super1(void **firstp, void *secondv)
         *  2 wrong uuid
         *  3 wrong other info
         */
-       struct mdp_superblock_1 *first = *firstp;
-       struct mdp_superblock_1 *second = secondv;
+       struct mdp_superblock_1 *first = st->sb;
+       struct mdp_superblock_1 *second = tst->sb;
 
        if (second->magic != __cpu_to_le32(MD_SB_MAGIC))
                return 1;
@@ -968,7 +970,7 @@ static int compare_super1(void **firstp, void *secondv)
                               sizeof(struct misc_dev_info));
                memcpy(first, second, 1024+sizeof(bitmap_super_t) +
                       sizeof(struct misc_dev_info));
-               *firstp = first;
+               st->sb = first;
                return 0;
        }
        if (memcmp(first->set_uuid, second->set_uuid, 16)!= 0)
@@ -1001,7 +1003,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
                /* guess... choose latest ctime */
                tst.ss = &super1;
                for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) {
-                       switch(load_super1(st, fd, sbp, devname)) {
+                       switch(load_super1(&tst, fd, sbp, devname)) {
                        case 0: super = *sbp;
                                if (bestvers == -1 ||
                                    bestctime < __le64_to_cpu(super->ctime)) {
@@ -1020,7 +1022,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
                        tst.minor_version = bestvers;
                        tst.ss = &super1;
                        tst.max_devs = 384;
-                       rv = load_super1(st, fd, sbp, devname);
+                       rv = load_super1(&tst, fd, sbp, devname);
                        if (rv == 0)
                                *st = tst;
                        return rv;
@@ -1105,6 +1107,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
                free(super);
                return 2;
        }
+       st->sb = super;
        *sbp = super;
 
        bsb = (struct bitmap_super_s *)(((char*)super)+1024);
@@ -1124,7 +1127,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
            != sizeof(struct bitmap_super_s))
                goto no_bitmap;
 
-       uuid_from_super1(uuid, super);
+       uuid_from_super1(st, uuid, super);
        if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
            memcmp(bsb->uuid, uuid, 16) != 0)
                goto no_bitmap;
@@ -1143,6 +1146,7 @@ static struct supertype *match_metadata_desc1(char *arg)
 
        st->ss = &super1;
        st->max_devs = 384;
+       st->sb = NULL;
        if (strcmp(arg, "1.0") == 0) {
                st->minor_version = 0;
                return st;
@@ -1301,7 +1305,7 @@ add_internal_bitmap1(struct supertype *st, void *sbv,
        memset(bms, 0, sizeof(*bms));
        bms->magic = __cpu_to_le32(BITMAP_MAGIC);
        bms->version = __cpu_to_le32(major);
-       uuid_from_super1((int*)bms->uuid, sb);
+       uuid_from_super1(st, (int*)bms->uuid, sb);
        bms->chunksize = __cpu_to_le32(chunk);
        bms->daemon_sleep = __cpu_to_le32(delay);
        bms->sync_size = __cpu_to_le64(size);
@@ -1366,6 +1370,12 @@ static int write_bitmap1(struct supertype *st, int fd, void *sbv)
        return rv;
 }
 
+static void free_super1(struct supertype *st, void *super)
+{
+       if (super)
+               free(super);
+}
+
 struct superswitch super1 = {
 #ifndef MDASSEMBLE
        .examine_super = examine_super1,
@@ -1389,6 +1399,7 @@ struct superswitch super1 = {
        .add_internal_bitmap = add_internal_bitmap1,
        .locate_bitmap = locate_bitmap1,
        .write_bitmap = write_bitmap1,
+       .free_super = free_super1,
        .major = 1,
 #if __BYTE_ORDER == BIG_ENDIAN
        .swapuuid = 0,