]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super0.c
Having single function to read mdmon pid file.
[thirdparty/mdadm.git] / super0.c
index 92255c23cbec0f9f7e1776377bce2db03021a0d2..5c6b7d71984e831ba0b9640e04b0f6093aa85022 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);
@@ -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)
-                               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);
@@ -154,6 +149,10 @@ static void examine_super0(struct supertype *st, char *homehost)
                                c = map_num(r5layout, sb->new_layout);
                                printf("     New Layout : %s\n", c?c:"-unknown-");
                        }
+                       if (sb->level == 6) {
+                               c = map_num(r6layout, sb->new_layout);
+                               printf("     New Layout : %s\n", c?c:"-unknown-");
+                       }
                        if (sb->level == 10) {
                                printf("     New Layout : near=%d, %s=%d\n",
                                       sb->new_layout&255,
@@ -187,6 +186,10 @@ static void examine_super0(struct supertype *st, char *homehost)
                c = map_num(r5layout, sb->layout);
                printf("         Layout : %s\n", c?c:"-unknown-");
        }
+       if (sb->level == 6) {
+               c = map_num(r6layout, sb->layout);
+               printf("         Layout : %s\n", c?c:"-unknown-");
+       }
        if (sb->level == 10) {
                printf("         Layout :");
                print_r10_layout(sb->layout);
@@ -207,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];
@@ -232,7 +235,7 @@ static void examine_super0(struct supertype *st, char *homehost)
        }
 }
 
-static void brief_examine_super0(struct supertype *st)
+static void brief_examine_super0(struct supertype *st, int verbose)
 {
        mdp_super_t *sb = st->sb;
        char *c=map_num(pers, sb->level);
@@ -240,14 +243,18 @@ static void brief_examine_super0(struct supertype *st)
 
        sprintf(devname, "/dev/md%d", sb->md_minor);
 
-       printf("ARRAY %s level=%s num-devices=%d UUID=",
-              devname,
-              c?c:"-unknown-", sb->raid_disks);
+       if (verbose) {
+               printf("ARRAY %s level=%s num-devices=%d",
+                      devname,
+                      c?c:"-unknown-", sb->raid_disks);
+       } else
+               printf("ARRAY %s", devname);
+
        if (sb->minor_version >= 90)
-               printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
+               printf(" UUID=%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
                       sb->set_uuid2, sb->set_uuid3);
        else
-               printf("%08x", sb->set_uuid0);
+               printf(" UUID=%08x", sb->set_uuid0);
        printf("\n");
 }
 
@@ -306,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);
 }
@@ -361,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;
@@ -368,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;
 
@@ -465,7 +479,14 @@ 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))
+               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)
                    != info->disk.state) {
                        sb->disks[d].state = info->disk.state | wonly;
                        rv = 1;
@@ -545,7 +566,8 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
        mdp_super_t *sb;
        int spares;
 
-       if (posix_memalign((void**)&sb, 512, MD_SB_BYTES + sizeof(bitmap_super_t)) != 0) {
+       if (posix_memalign((void**)&sb, 4096,
+                          MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
                fprintf(stderr, Name ": %s could not allocate superblock\n", __func__);
                return 0;
        }
@@ -627,7 +649,7 @@ struct devinfo {
 
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
-static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
+static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
                          int fd, char *devname)
 {
        mdp_super_t *sb = st->sb;
@@ -652,6 +674,8 @@ static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        di->disk = *dinfo;
        di->next = NULL;
        *dip = di;
+
+       return 0;
 }
 #endif
 
@@ -680,8 +704,8 @@ static int store_super0(struct supertype *st, int fd)
        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)
-                       if (write(fd, bm, ROUND_UP(sizeof(*bm),512)) != 
-                           ROUND_UP(sizeof(*bm),512))
+                       if (write(fd, bm, ROUND_UP(sizeof(*bm),4096)) != 
+                           ROUND_UP(sizeof(*bm),4096))
                            return 5;
        }
 
@@ -702,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);
 
@@ -741,8 +765,9 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
        if (second->md_magic != MD_SB_MAGIC)
                return 1;
        if (!first) {
-               if (posix_memalign((void**)&first, 512, 
-                              MD_SB_BYTES + sizeof(struct bitmap_super_s)) != 0) {
+               if (posix_memalign((void**)&first, 4096,
+                            MD_SB_BYTES + 
+                            ROUND_UP(sizeof(struct bitmap_super_s), 4096)) != 0) {
                        fprintf(stderr, Name
                                ": %s could not allocate superblock\n", __func__);
                        return 1;
@@ -815,8 +840,9 @@ static int load_super0(struct supertype *st, int fd, char *devname)
                return 1;
        }
 
-       if (posix_memalign((void**)&super, 512,
-                          MD_SB_BYTES + sizeof(bitmap_super_t)+512) != 0) {
+       if (posix_memalign((void**)&super, 4096,
+                          MD_SB_BYTES +
+                          ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) {
                fprintf(stderr, Name
                        ": %s could not allocate superblock\n", __func__);
                return 1;
@@ -864,8 +890,8 @@ static int load_super0(struct supertype *st, int fd, char *devname)
         * valid.  If it doesn't clear the bit.  An --assemble --force
         * should get that written out.
         */
-       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),512))
-           != ROUND_UP(sizeof(struct bitmap_super_s),512))
+       if (read(fd, super+1, ROUND_UP(sizeof(struct bitmap_super_s),4096))
+           != ROUND_UP(sizeof(struct bitmap_super_s),4096))
                goto no_bitmap;
 
        uuid_from_super0(st, uuid);
@@ -896,9 +922,7 @@ 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 ||
-           strcmp(arg, "default") == 0 ||
-           strcmp(arg, "") == 0 /* no metadata */
+           strcmp(arg, "0.90") == 0
                )
                return st;
 
@@ -947,9 +971,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 (chunk < min_chunk)
                return 0; /* chunk size too small */
 
        sb->state |= (1<<MD_SB_BITMAP_PRESENT);
@@ -996,8 +1025,8 @@ static int write_bitmap0(struct supertype *st, int fd)
        int rv = 0;
 
        int towrite, n;
-       char abuf[4096+512];
-       char *buf = (char*)(((long)(abuf+512))&~511UL);
+       char abuf[4096+4096];
+       char *buf = (char*)(((long)(abuf+4096))&~4095L);
 
        if (!get_dev_size(fd, NULL, &dsize))
                return 1;
@@ -1051,12 +1080,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<<10))
+       }
+       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;
 
@@ -1076,7 +1115,7 @@ static int validate_geometry0(struct supertype *st, int level,
 
        if (ldsize < MD_RESERVED_SECTORS * 512)
                return 0;
-       if (size > (0x7fffffffULL<<10))
+       if (size > (0x7fffffffULL<<9))
                return 0;
        *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9);
        return 1;
@@ -1108,4 +1147,5 @@ struct superswitch super0 = {
        .locate_bitmap = locate_bitmap0,
        .write_bitmap = write_bitmap0,
        .free_super = free_super0,
+       .name = "0.90",
 };