]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Clarify when update=super-minor happens automatcially
[thirdparty/mdadm.git] / super0.c
index 7025445583e7b313409ade9fee8c6b2e1929ac7c..9e83193bddbadc20ecf0bb59edb24b7233eb8d72 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -27,8 +27,9 @@
  *           Australia
  */
 
+#define HAVE_STDINT_H 1
 #include "mdadm.h"
-#include <openssl/sha.h> /* 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);
 }
@@ -338,6 +347,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<<MD_DISK_SYNC)) &&
+                   (sb->disks[i].raid_disk < info->array.raid_disks) &&
                    (sb->disks[i].state & (1<<MD_DISK_ACTIVE)) &&
                    !(sb->disks[i].state & (1<<MD_DISK_FAULTY)))
                        working ++;
@@ -462,9 +472,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];
@@ -545,9 +556,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 +625,8 @@ static int store_super0(struct supertype *st, int fd, void *sbv)
        if (super->state & (1<<MD_SB_BITMAP_PRESENT)) {
                struct bitmap_super_s * bm = (struct bitmap_super_s*)(super+1);
                if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC)
-                       write(fd, bm, sizeof(*bm));
+                       if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
+                           return 5;
        }
 
        fsync(fd);
@@ -632,7 +645,6 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d
        }
 
        sb->disks[dinfo->number].state &= ~(1<<MD_DISK_FAULTY);
-       sb->disks[dinfo->number].state |= (1<<MD_DISK_SYNC);
 
        sb->this_disk = sb->disks[dinfo->number];
        sb->sb_csum = calc_sb0_csum(sb);