]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-intel.c
util: make env checking more generic
[thirdparty/mdadm.git] / super-intel.c
index df3184aae000fba5620b40f582505208e8e949ee..f5ce06bdacb055f5373369d076e800eb8e7b983b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * mdadm - Intel(R) Matrix Storage Manager Support
  *
- * Copyright (C) 2002-2007 Intel Corporation
+ * Copyright (C) 2002-2008 Intel Corporation
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -213,17 +213,6 @@ struct imsm_update_add_disk {
        enum imsm_update_type type;
 };
 
-static int imsm_env_devname_as_serial(void)
-{
-       char *val = getenv("IMSM_DEVNAME_AS_SERIAL");
-
-       if (val && atoi(val) == 1)
-               return 1;
-
-       return 0;
-}
-
-
 static struct supertype *match_metadata_desc_imsm(char *arg)
 {
        struct supertype *st;
@@ -493,6 +482,8 @@ static __u32 imsm_reserved_sectors(struct intel_super *super, struct dl *dl)
 }
 
 #ifndef MDASSEMBLE
+static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info);
+
 static void print_imsm_dev(struct imsm_dev *dev, int index)
 {
        __u64 sz;
@@ -501,7 +492,7 @@ static void print_imsm_dev(struct imsm_dev *dev, int index)
        __u32 ord;
 
        printf("\n");
-       printf("[%s]:\n", dev->volume);
+       printf("[%.16s]:\n", dev->volume);
        printf("     RAID Level : %d\n", get_imsm_raid_level(map));
        printf("        Members : %d\n", map->num_members);
        for (slot = 0; slot < map->num_members; slot++)
@@ -571,15 +562,21 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
        struct imsm_super *mpb = super->anchor;
        char str[MAX_SIGNATURE_LENGTH];
        int i;
+       struct mdinfo info;
+       char nbuf[64];
        __u32 sum;
        __u32 reserved = imsm_reserved_sectors(super, super->disks);
 
+
        snprintf(str, MPB_SIG_LEN, "%s", mpb->sig);
        printf("          Magic : %s\n", str);
        snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb));
        printf("        Version : %s\n", get_imsm_version(mpb));
        printf("         Family : %08x\n", __le32_to_cpu(mpb->family_num));
        printf("     Generation : %08x\n", __le32_to_cpu(mpb->generation_num));
+       getinfo_super_imsm(st, &info);
+       fname_from_uuid(st, &info, nbuf,'-');
+       printf("           UUID : %s\n", nbuf + 5);
        sum = __le32_to_cpu(mpb->check_sum);
        printf("       Checksum : %08x %s\n", sum,
                __gen_imsm_checksum(mpb) == sum ? "correct" : "incorrect");
@@ -611,14 +608,27 @@ static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info);
 
 static void brief_examine_super_imsm(struct supertype *st)
 {
-       /* We just write a generic DDF ARRAY entry
-        */
+       /* We just write a generic IMSM ARRAY entry */
        struct mdinfo info;
        char nbuf[64];
+       struct intel_super *super = st->sb;
+       int i;
+
+       if (!super->anchor->num_raid_devs)
+               return;
 
        getinfo_super_imsm(st, &info);
        fname_from_uuid(st, &info, nbuf,'-');
-       printf("ARRAY /dev/imsm metadata=imsm UUID=%s\n", nbuf + 5);
+       printf("ARRAY /dev/imsm metadata=imsm auto=md UUID=%s\n", nbuf + 5);
+       for (i = 0; i < super->anchor->num_raid_devs; i++) {
+               struct imsm_dev *dev = get_imsm_dev(super, i);
+
+               super->current_vol = i;
+               getinfo_super_imsm(st, &info);
+               fname_from_uuid(st, &info, nbuf,'-');
+               printf("ARRAY /dev/md/%.16s container=/dev/imsm member=%d auto=mdp UUID=%s\n",
+                      dev->volume, i, nbuf + 5);
+       }
 }
 
 static void detail_super_imsm(struct supertype *st, char *homehost)
@@ -811,16 +821,21 @@ static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info)
                __u32 reserved = imsm_reserved_sectors(super, super->disks);
 
                disk = &super->disks->disk;
-               info->disk.number = super->disks->index;
-               info->disk.raid_disk = super->disks->index;
                info->data_offset = __le32_to_cpu(disk->total_blocks) - reserved;
                info->component_size = reserved;
                s = __le32_to_cpu(disk->status);
                info->disk.state  = s & CONFIGURED_DISK ? (1 << MD_DISK_ACTIVE) : 0;
                info->disk.state |= s & FAILED_DISK ? (1 << MD_DISK_FAULTY) : 0;
-               info->disk.state |= s & USABLE_DISK ? (1 << MD_DISK_SYNC) : 0;
+               info->disk.state |= s & SPARE_DISK ? 0 : (1 << MD_DISK_SYNC);
        }
-       uuid_from_super_imsm(st, info->uuid);
+
+       /* only call uuid_from_super_imsm when this disk is part of a populated container,
+        * ->compare_super may have updated the 'num_raid_devs' field for spares
+        */
+       if (info->disk.state & (1 << MD_DISK_SYNC) || super->anchor->num_raid_devs)
+               uuid_from_super_imsm(st, info->uuid);
+       else
+               memcpy(info->uuid, uuid_match_any, sizeof(int[4]));
 }
 
 static int update_super_imsm(struct supertype *st, struct mdinfo *info,
@@ -926,6 +941,24 @@ static int compare_super_imsm(struct supertype *st, struct supertype *tst)
         */
        if (first->anchor->num_raid_devs == 0 &&
            sec->anchor->num_raid_devs > 0) {
+               int i;
+
+               /* we need to copy raid device info from sec if an allocation
+                * fails here we don't associate the spare
+                */
+               for (i = 0; i < sec->anchor->num_raid_devs; i++) {
+                       first->dev_tbl[i] = malloc(sizeof(struct imsm_dev));
+                       if (!first->dev_tbl) {
+                               while (--i >= 0) {
+                                       free(first->dev_tbl[i]);
+                                       first->dev_tbl[i] = NULL;
+                               }
+                               fprintf(stderr, "imsm: failed to associate spare\n"); 
+                               return 3;
+                       }
+                       *first->dev_tbl[i] = *sec->dev_tbl[i];
+               }
+
                first->anchor->num_raid_devs = sec->anchor->num_raid_devs;
                first->anchor->family_num = sec->anchor->family_num;
        }
@@ -973,7 +1006,7 @@ static int imsm_read_serial(int fd, char *devname,
 
        rv = scsi_get_serial(fd, scsi_serial, sizeof(scsi_serial));
 
-       if (rv && imsm_env_devname_as_serial()) {
+       if (rv && check_env("IMSM_DEVNAME_AS_SERIAL")) {
                memset(serial, 0, MAX_RAID_SERIAL_LEN);
                fd2devname(fd, (char *) serial);
                return 0;
@@ -2439,7 +2472,8 @@ static __u8 imsm_check_degraded(struct intel_super *super, struct imsm_dev *dev,
                 * slot+1
                 */
                int i;
-               int insync;
+               /* gcc -Os complains that this is unused */
+               int insync = insync;
 
                for (i = 0; i < map->num_members; i++) {
                        __u32 ord = get_imsm_ord_tbl_ent(dev, i);
@@ -2884,6 +2918,8 @@ static struct mdinfo *imsm_activate_spare(struct active_array *a,
  
                /* found a usable disk with enough space */
                di = malloc(sizeof(*di));
+               if (!di)
+                       continue;
                memset(di, 0, sizeof(*di));
 
                /* dl->index will be -1 in the case we are activating a
@@ -2923,7 +2959,23 @@ static struct mdinfo *imsm_activate_spare(struct active_array *a,
         * disk_ord_tbl for the array
         */
        mu = malloc(sizeof(*mu));
-       mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares);
+       if (mu) {
+               mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares);
+               if (mu->buf == NULL) {
+                       free(mu);
+                       mu = NULL;
+               }
+       }
+       if (!mu) {
+               while (rv) {
+                       struct mdinfo *n = rv->next;
+
+                       free(rv);
+                       rv = n;
+               }
+               return NULL;
+       }
+                       
        mu->space = NULL;
        mu->len = sizeof(struct imsm_update_activate_spare) * num_spares;
        mu->next = *updates;
@@ -3182,6 +3234,8 @@ static void imsm_process_update(struct supertype *st,
                 * being added */
                if (super->add) {
                        struct active_array *a;
+
+                       super->updates_pending++;
                        for (a = st->arrays; a; a = a->next)
                                a->check_degraded = 1;
                }