]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Add 'supertype' arg to almost all metadata methods.
[thirdparty/mdadm.git] / super0.c
index 0396c2cd81b4e26074de176c00444d1f818e45c9..b81037ed67a08a5dcc0359ea93adcaa3ed1c9c3d 100644 (file)
--- 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,7 +85,7 @@ 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, void *sbv, char *homehost)
 {
        mdp_super_t *sb = sbv;
        time_t atime;
@@ -231,7 +231,7 @@ static void examine_super0(void *sbv, char *homehost)
        }
 }
 
-static void brief_examine_super0(void *sbv)
+static void brief_examine_super0(struct supertype *st, void *sbv)
 {
        mdp_super_t *sb = sbv;
        char *c=map_num(pers, sb->level);
@@ -250,7 +250,7 @@ static void brief_examine_super0(void *sbv)
        printf("\n");
 }
 
-static void detail_super0(void *sbv, char *homehost)
+static void detail_super0(struct supertype *st, void *sbv, char *homehost)
 {
        mdp_super_t *sb = sbv;
        printf("           UUID : ");
@@ -270,7 +270,7 @@ 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, void *sbv)
 {
        mdp_super_t *sb = sbv;
        printf(" UUID=");
@@ -281,7 +281,7 @@ static void brief_detail_super0(void *sbv)
                printf("%08x", sb->set_uuid0);
 }
 
-static void export_super0(void *sbv)
+static void export_super0(struct supertype *st, void *sbv)
 {
        mdp_super_t *sb = sbv;
        printf("MD_UUID=");
@@ -294,7 +294,7 @@ static void export_super0(void *sbv)
 }
 #endif
 
-static int match_home0(void *sbv, char *homehost)
+static int match_home0(struct supertype *st, void *sbv, char *homehost)
 {
        mdp_super_t *sb = sbv;
        char buf[20];
@@ -305,7 +305,7 @@ 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], void * sbv)
 {
        mdp_super_t *super = sbv;
        uuid[0] = super->set_uuid0;
@@ -320,7 +320,7 @@ 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, void *sbv)
 {
        mdp_super_t *sb = sbv;
        int working = 0;
@@ -348,7 +348,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, sbv);
 
        if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
                info->reshape_active = 1;
@@ -372,7 +372,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,
+                        void *sbv, char *update,
                         char *devname, int verbose,
                         int uuid_set, char *homehost)
 {
@@ -403,14 +404,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 +508,7 @@ static int update_super0(struct mdinfo *info, void *sbv, char *update,
                if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) {
                        struct bitmap_super_s *bm;
                        bm = (struct bitmap_super_s*)(sb+1);
-                       uuid_from_super0((int*)bm->uuid, sbv);
+                       uuid_from_super0(st, (int*)bm->uuid, sbv);
                }
        }
        if (strcmp(update, "_reshape_progress")==0)
@@ -603,7 +604,7 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
 }
 
 /* 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, void *sbv, mdu_disk_info_t *dinfo)
 {
        mdp_super_t *sb = sbv;
        mdp_disk_t *dk = &sb->disks[dinfo->number];
@@ -696,8 +697,8 @@ static int compare_super0(void **firstp, void *secondv)
                return 0;
        }
 
-       uuid_from_super0(uuid1, first);
-       uuid_from_super0(uuid2, second);
+       uuid_from_super0(NULL, uuid1, first);
+       uuid_from_super0(NULL, uuid2, second);
        if (!same_uuid(uuid1, uuid2, 0))
                return 2;
        if (first->major_version != second->major_version ||
@@ -727,7 +728,7 @@ 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;
-    
+
        if (!get_dev_size(fd, devname, &dsize))
                return 1;
 
@@ -798,7 +799,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, super);
        bsb = (struct bitmap_super_s *)(super+1);
        if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
            memcmp(bsb->uuid, uuid, 16) != 0)
@@ -875,7 +876,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, sb);
        bms->chunksize = __cpu_to_le32(chunk);
        bms->daemon_sleep = __cpu_to_le32(delay);
        bms->sync_size = __cpu_to_le64(size);
@@ -910,7 +911,7 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
        unsigned long long dsize;
        unsigned long long offset;
        mdp_super_t *sb = sbv;
-    
+
        int rv = 0;
 
        int towrite, n;
@@ -938,7 +939,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,6 +954,12 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
        return rv;
 }
 
+static void free_super0(struct supertype *st, void *super)
+{
+       if (super)
+               free(super);
+}
+
 struct superswitch super0 = {
 #ifndef MDASSEMBLE
        .examine_super = examine_super0,
@@ -976,6 +983,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,
 };