]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Compile with -Wextra by default
[thirdparty/mdadm.git] / super0.c
index 71b03240458bbfa360564a49548a502eb37351db..ae3e8855193f9d6183776f346779b6d29ba5ef5c 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  *    Author: Neil Brown
- *    Email: <neilb@cse.unsw.edu.au>
- *    Paper: Neil Brown
- *           School of Computer Science and Engineering
- *           The University of New South Wales
- *           Sydney, 2052
- *           Australia
+ *    Email: <neilb@suse.de>
  */
 
 #define HAVE_STDINT_H 1
@@ -90,6 +85,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        mdp_super_t *sb = st->sb;
        time_t atime;
        int d;
+       int delta_extra = 0;
        char *c;
 
        printf("          Magic : %08x\n", sb->md_magic);
@@ -117,7 +113,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        printf("  Creation Time : %.24s\n", ctime(&atime));
        c=map_num(pers, sb->level);
        printf("     Raid Level : %s\n", c?c:"-unknown-");
-       if ((int)sb->level >= 0) {
+       if ((int)sb->level > 0) {
                int ddsks=0;
                printf("  Used Dev Size : %d%s\n", sb->size,
                       human_size((long long)sb->size<<10));
@@ -140,10 +136,9 @@ static void examine_super0(struct supertype *st, char *homehost)
                printf("  Reshape pos'n : %llu%s\n", (unsigned long long)sb->reshape_position/2, human_size((long long)sb->reshape_position<<9));
                if (sb->delta_disks) {
                        printf("  Delta Devices : %d", sb->delta_disks);
-                       if (sb->delta_disks > 0)
-                               printf(" (%d->%d)\n", sb->raid_disks-sb->delta_disks, sb->raid_disks);
-                       else
-                               printf(" (%d->%d)\n", sb->raid_disks, sb->raid_disks+sb->delta_disks);
+                       printf(" (%d->%d)\n", sb->raid_disks-sb->delta_disks, sb->raid_disks);
+                       if (((int)sb->delta_disks) < 0)
+                               delta_extra = - sb->delta_disks;
                }
                if (sb->new_level != sb->level) {
                        c = map_num(pers, sb->new_level);
@@ -215,7 +210,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        }
        printf("\n");
        printf("      Number   Major   Minor   RaidDevice State\n");
-       for (d= -1; d<(signed int)(sb->raid_disks+sb->spare_disks); d++) {
+       for (d= -1; d<(signed int)(sb->raid_disks+delta_extra + sb->spare_disks); d++) {
                mdp_disk_t *dp;
                char *dv;
                char nb[5];
@@ -318,9 +313,13 @@ static int match_home0(struct supertype *st, char *homehost)
 {
        mdp_super_t *sb = st->sb;
        char buf[20];
-       char *hash = sha1_buffer(homehost,
-                                strlen(homehost),
-                                buf);
+       char *hash;
+
+       if (!homehost)
+               return 0;
+       hash = sha1_buffer(homehost,
+                          strlen(homehost),
+                          buf);
 
        return (memcmp(&sb->set_uuid2, hash, 8)==0);
 }
@@ -373,6 +372,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info)
 
        uuid_from_super0(st, info->uuid);
 
+       info->recovery_start = MaxSector;
        if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
                info->reshape_active = 1;
                info->reshape_progress = sb->reshape_position;
@@ -380,6 +380,8 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info)
                info->delta_disks = sb->delta_disks;
                info->new_layout = sb->new_layout;
                info->new_chunk = sb->new_chunk;
+               if (info->delta_disks < 0)
+                       info->array.raid_disks -= info->delta_disks;
        } else
                info->reshape_active = 0;
 
@@ -387,7 +389,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info)
        /* 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].raid_disk < (unsigned)info->array.raid_disks) &&
                    (sb->disks[i].state & (1<<MD_DISK_ACTIVE)) &&
                    !(sb->disks[i].state & (1<<MD_DISK_FAULTY)))
                        working ++;
@@ -425,7 +427,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                                devname, info->array.md_minor);
        }
        if (strcmp(update, "summaries") == 0) {
-               int i;
+               unsigned int i;
                /* set nr_disks, active_disks, working_disks,
                 * failed_disks, spare_disks based on disks[]
                 * array in superblock.
@@ -477,8 +479,15 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
        if (strcmp(update, "assemble")==0) {
                int d = info->disk.number;
                int wonly = sb->disks[d].state & (1<<MD_DISK_WRITEMOSTLY);
-               if ((sb->disks[d].state & ~(1<<MD_DISK_WRITEMOSTLY))
-                   != info->disk.state) {
+               int mask = (1<<MD_DISK_WRITEMOSTLY);
+               int add = 0;
+               if (sb->minor_version >= 91)
+                       /* During reshape we don't insist on everything
+                        * being marked 'sync'
+                        */
+                       add = (1<<MD_DISK_SYNC);
+               if (((sb->disks[d].state & ~mask) | add)
+                   != (unsigned)info->disk.state) {
                        sb->disks[d].state = info->disk.state | wonly;
                        rv = 1;
                }
@@ -584,7 +593,7 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
        sb->gvalid_words = 0; /* ignored */
        sb->ctime = time(0);
        sb->level = info->level;
-       if (size != info->size)
+       if (size != (unsigned long long)info->size)
                return 0;
        sb->size = info->size;
        sb->nr_disks = info->nr_disks;
@@ -717,8 +726,8 @@ static int write_init_super0(struct supertype *st)
                        continue;
                if (di->fd == -1)
                        continue;
-               Kill(di->devname, 0, 1, 1);
-               Kill(di->devname, 0, 1, 1);
+               while (Kill(di->devname, NULL, 0, 1, 1) == 0)
+                       ;
 
                sb->disks[di->disk.number].state &= ~(1<<MD_DISK_FAULTY);
 
@@ -913,9 +922,11 @@ static struct supertype *match_metadata_desc0(char *arg)
        while (arg[0] == '0' && arg[1] == '0')
                arg++;
        if (strcmp(arg, "0") == 0 ||
-           strcmp(arg, "0.90") == 0 ||
+#ifdef DEFAULT_OLD_METADATA /* ifndef in super1.c */
            strcmp(arg, "default") == 0 ||
-           strcmp(arg, "") == 0 /* no metadata */
+#endif /* DEFAULT_OLD_METADATA */
+           strcmp(arg, "0.90") == 0 ||
+           strcmp(arg, "") == 0 /* no metadata  - i.e. non_persistent */
                )
                return st;
 
@@ -951,7 +962,7 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
         * size is in sectors,  chunk is in bytes !!!
         */
        unsigned long long bits;
-       unsigned long long max_bits = 60*1024*8;
+       unsigned long long max_bits = (60*1024 - sizeof(bitmap_super_t))*8;
        unsigned long long min_chunk;
        int chunk = *chunkp;
        mdp_super_t *sb = st->sb;
@@ -964,9 +975,14 @@ static int add_internal_bitmap0(struct supertype *st, int *chunkp,
                min_chunk *= 2;
                bits = (bits+1)/2;
        }
-       if (chunk == UnSet)
+       if (chunk == UnSet) {
+               /* A chunk size less than a few Megabytes gives poor
+                * performance without increasing resync noticeably
+                */
                chunk = min_chunk;
-       else if (chunk < min_chunk)
+               if (chunk < 64*1024*1024)
+                       chunk = 64*1024*1024;
+       } else if ((unsigned long long)chunk < min_chunk)
                return 0; /* chunk size too small */
 
        sb->state |= (1<<MD_SB_BITMAP_PRESENT);
@@ -1032,7 +1048,7 @@ static int write_bitmap0(struct supertype *st, int fd)
 
        memset(buf, 0xff, 4096);
        memcpy(buf,  ((char*)sb)+MD_SB_BYTES, sizeof(bitmap_super_t));
-       towrite = 64*1024;
+       towrite = 60*1024;
        while (towrite > 0) {
                n = towrite;
                if (n > 4096)
@@ -1068,12 +1084,22 @@ static int validate_geometry0(struct supertype *st, int level,
        unsigned long long ldsize;
        int fd;
 
-       if (level == LEVEL_CONTAINER)
+       if (level == LEVEL_CONTAINER) {
+               if (verbose)
+                       fprintf(stderr, Name ": 0.90 metadata does not support containers\n");
                return 0;
-       if (raiddisks > MD_SB_DISKS)
+       }
+       if (raiddisks > MD_SB_DISKS) {
+               if (verbose)
+                       fprintf(stderr, Name ": 0.90 metadata supports at most %d devices per array\n",
+                               MD_SB_DISKS);
                return 0;
-       if (size > (0x7fffffffULL<<9))
+       }
+       if (size > (0x7fffffffULL<<9)) {
+               if (verbose)
+                       fprintf(stderr, Name ": 0.90 metadata supports at most 2 terrabytes per device\n");
                return 0;
+       }
        if (!subdev)
                return 1;