]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Merge branch 'master' into devel-3.0
authorNeil Brown <neilb@suse.de>
Thu, 19 Jun 2008 06:38:37 +0000 (16:38 +1000)
committerNeil Brown <neilb@suse.de>
Thu, 19 Jun 2008 06:38:37 +0000 (16:38 +1000)
Conflicts:

Makefile

1  2 
Assemble.c
Makefile
ReadMe.c
mdadm.c
super0.c

diff --combined Assemble.c
index 16f45cdf1ddc6bd21afa95ffec6e91e29633ed74,79f091269e68f843cbf9bd03978b8c739f3cf80c..cb2725db5ebe6db9a48606a0b67bd852cc295690
@@@ -367,7 -367,8 +367,8 @@@ int Assemble(struct supertype *st, cha
                tmpdev->used = 1;
  
        loop:
-               tst->ss->free_super(tst);
+               if (tst)
+                       tst->ss->free_super(tst);
        }
  
        if (mdfd < 0) {
                 */
                mdu_array_info_t inf;
                char *c;
-               if (!st->sb) {
+               if (!st || !st->sb) {
                        return 2;
                }
                st->ss->getinfo_super(st, &info);
                devcnt++;
        }
  
-       if (update && strcmp(update, "byteorder")==0)
-               st->minor_version = 90;
        if (devcnt == 0) {
                fprintf(stderr, Name ": no devices found for %s\n",
                        mddev);
-               st->ss->free_super(st);
+               if (st)
+                       st->ss->free_super(st);
                if (must_close) close(mdfd);
                return 1;
        }
  
+       if (update && strcmp(update, "byteorder")==0)
+               st->minor_version = 90;
        st->ss->getinfo_super(st, &info);
        clean = info.array.state & 1;
  
                        continue;
                }
                tst = dup_super(st);
-               if (tst->ss->load_super(st,fd, NULL)) {
+               if (tst->ss->load_super(tst,fd, NULL)) {
                        close(fd);
                        fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n",
                                devices[chosen_drive].devname);
        /* Almost ready to actually *do* something */
        if (!old_linux) {
                int rv;
 +
 +#ifndef MDASSEMBLE
 +              struct mdinfo *sra;
 +              if (st->ss->external) {
 +                      char ver[100];
 +                      strcat(strcpy(ver, "external:"), info.text_version);
 +                      sra = sysfs_read(mdfd, 0, 0);
 +                      if ((vers % 100) < 2 ||
 +                          sra == NULL ||
 +                          sysfs_set_str(sra, NULL, "metadata_version",
 +                                        ver) < 0) {
 +                              fprintf(stderr, Name ": This kernel does not "
 +                                      "support external metadata.\n");
 +                              return 1;
 +                      }
 +                      rv = sysfs_set_array(sra, &info);
 +              } else
 +#endif
                if ((vers % 100) >= 1) { /* can use different versions */
                        mdu_array_info_t inf;
                        memset(&inf, 0, sizeof(inf));
                                j = chosen_drive;
  
                        if (j >= 0 /* && devices[j].uptodate */) {
 -                              if (ioctl(mdfd, ADD_NEW_DISK,
 -                                        &devices[j].i.disk)!=0) {
 +#ifndef MDASSEMBLE
 +                              if (st->ss->external) {
 +                                      devices[j].i.disk.number =
 +                                              devices[j].i.disk.raid_disk;
 +                                      st->ss->getinfo_super_n(st,
 +                                                              &devices[j].i);
 +                                      rv = sysfs_add_disk(sra,
 +                                                          &devices[j].i);
 +                              } else
 +#endif
 +                                      rv = ioctl(mdfd, ADD_NEW_DISK,
 +                                        &devices[j].i.disk);
 +                              if (rv) {
                                        fprintf(stderr, Name ": failed to add "
                                                        "%s to %s: %s\n",
                                                devices[j].devname,
                                        i, mddev);
                }
  
 +              if (info.array.level == LEVEL_CONTAINER) {
 +                      if (verbose >= 0) {
 +                              fprintf(stderr, Name ": Container %s has been "
 +                                      "assembled with %d drive%s",
 +                                      mddev, okcnt, okcnt==1?"":"s");
 +                              if (okcnt < info.array.raid_disks)
 +                                      fprintf(stderr, " (out of %d)",
 +                                              info.array.raid_disks);
 +                              fprintf(stderr, "\n");
 +                      }
 +                      if (must_close)
 +                              close(mdfd);
 +                      return 0;
 +              }
 +
                if (runstop == 1 ||
                    (runstop <= 0 &&
                     ( enough(info.array.level, info.array.raid_disks,
                                        /* There is a nasty race with 'mdadm --monitor'.
                                         * If it opens this device before we close it,
                                         * it gets an incomplete open on which IO
 -                                       * doesn't work and the capacity if wrong.
 +                                       * doesn't work and the capacity is
 +                                       * wrong.
                                         * If we reopen (to check for layered devices)
                                         * before --monitor closes, we loose.
                                         *
                                        "start the array while not clean "
                                        "- consider --force.\n");
  
-                       if (must_close) close(mdfd);
+                       if (must_close) {
+                               ioctl(mdfd, STOP_ARRAY, NULL);
+                               close(mdfd);
+                       }
                        return 1;
                }
                if (runstop == -1) {
                                fprintf(stderr, " (use --run to insist).\n");
                        }
                }
-               if (must_close) close(mdfd);
+               if (must_close) {
+                       ioctl(mdfd, STOP_ARRAY, NULL);
+                       close(mdfd);
+               }
                return 1;
        } else {
                /* The "chosen_drive" is a good choice, and if necessary, the superblock has
diff --combined Makefile
index 68b3891870fe601c4ed283f420e85852fdd3a2b9,2b3c84cbb1094da3b41c9d5da0ee4ef9d999ad74..409df2101350fe1a15a30f220a1b0039b901fd76
+++ b/Makefile
@@@ -69,34 -69,30 +69,35 @@@ MAN8DIR = $(MANDIR)/man
  OBJS =  mdadm.o config.o mdstat.o  ReadMe.o util.o Manage.o Assemble.o Build.o \
        Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
        Incremental.o \
 -      mdopen.o super0.o super1.o bitmap.o restripe.o sysfs.o sha1.o \
 -      mapfile.o
 +      mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \
 +      restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o
  SRCS =  mdadm.c config.c mdstat.c  ReadMe.c util.c Manage.c Assemble.c Build.c \
        Create.c Detail.c Examine.c Grow.c Monitor.c dlink.c Kill.c Query.c \
        Incremental.c \
 -      mdopen.c super0.c super1.c bitmap.c restripe.c sysfs.c sha1.c \
 -      mapfile.c
 +      mdopen.c super0.c super1.c super-ddf.c super-intel.c bitmap.c \
 +      restripe.c sysfs.c sha1.c mapfile.c crc32.c sg_io.c msg.c
 +
 +MON_OBJS = mdmon.o monitor.o managemon.o util.o mdstat.o sysfs.o config.o \
 +      Kill.o sg_io.o dlink.o ReadMe.o super0.o super1.o super-intel.o \
 +      super-ddf.o sha1.o crc32.o msg.o
 +
  
  STATICSRC = pwgr.c
  STATICOBJS = pwgr.o
  
  ASSEMBLE_SRCS := mdassemble.c Assemble.c Manage.c config.c dlink.c util.c \
 -      super0.c super1.c sha1.c
 +      super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c
+ ASSEMBLE_AUTO_SRCS := mdopen.c mdstat.c sysfs.c
  ASSEMBLE_FLAGS:= $(CFLAGS) -DMDASSEMBLE
  ifdef MDASSEMBLE_AUTO
- ASSEMBLE_SRCS += mdopen.c mdstat.c
+ ASSEMBLE_SRCS += $(ASSEMBLE_AUTO_SRCS)
  ASSEMBLE_FLAGS += -DMDASSEMBLE_AUTO
  endif
  
 -all : mdadm mdadm.man md.man mdadm.conf.man
 +all : mdadm mdmon mdadm.man md.man mdadm.conf.man
  
  everything: all mdadm.static swap_super test_stripe \
-       mdassemble mdassemble.static mdassemble.man \
+       mdassemble mdassemble.auto mdassemble.static mdassemble.man \
        mdadm.Os mdadm.O2
  # mdadm.uclibc and mdassemble.uclibc don't work on x86-64
  # mdadm.tcc doesn't work..
@@@ -123,10 -119,6 +124,10 @@@ mdadm.Os : $(SRCS) mdadm.
  mdadm.O2 : $(SRCS) mdadm.h
        gcc -o mdadm.O2 $(CFLAGS)  -DHAVE_STDINT_H -O2 $(SRCS)
  
 +mdmon : $(MON_OBJS)
 +      $(CC) $(LDFLAGS) -o mdmon $(MON_OBJS) $(LDLIBS)
 +msg.o: msg.c msg.h
 +
  test_stripe : restripe.c mdadm.h
        $(CC) $(CXFLAGS) $(LDFLAGS) -o test_stripe -DMAIN restripe.c
  
@@@ -138,6 -130,11 +139,11 @@@ mdassemble.static : $(ASSEMBLE_SRCS) md
        rm -f $(OBJS)
        $(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) $(STATICSRC)
  
+ mdassemble.auto : $(ASSEMBLE_SRCS) mdadm.h $(ASSEMBLE_AUTO_SRCS)
+       rm -f mdassemble.static
+       $(MAKE) MDASSEMBLE_AUTO=1 mdassemble.static
+       mv mdassemble.static mdassemble.auto
  mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h
        rm -f $(OJS)
        $(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) $(STATICSRC)
@@@ -191,10 -188,10 +197,11 @@@ test: mdadm test_stripe swap_supe
        @echo "Please run 'sh ./test' as root"
  
  clean : 
 -      rm -f mdadm $(OBJS) $(STATICOBJS) core *.man mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt \
 +      rm -f mdadm mdmon $(OBJS) $(MON_OBJS) $(STATICOBJS) core *.man \
 +      mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt \
        mdadm.Os mdadm.O2 \
-       mdassemble mdassemble.static mdassemble.uclibc mdassemble.klibc swap_super \
+       mdassemble mdassemble.static mdassemble.auto mdassemble.uclibc \
+       mdassemble.klibc swap_super \
        init.cpio.gz mdadm.uclibc.static test_stripe
  
  dist : clean
diff --combined ReadMe.c
index a52f0800af49118d539099af2b6087fda4ba0170,0a736ed7b4af29838dbaab24ecbbbcd3bdfdbac5..3fae1930654bdca81d099466648c8e94d2aab890
+++ b/ReadMe.c
@@@ -24,7 -24,7 +24,7 @@@
  
  #include "mdadm.h"
  
- char Version[] = Name " - v2.6.5 - 15th May 2008\n";
+ char Version[] = Name " - v2.6.7 - 6th June 2008\n";
  
  /*
   * File: ReadMe.c
@@@ -610,7 -610,6 +610,7 @@@ mapping_t pers[] = 
        { "raid10", 10},
        { "10", 10},
        { "faulty", LEVEL_FAULTY},
 +      { "container", LEVEL_CONTAINER},
        { NULL, 0}
  };
  
diff --combined mdadm.c
index 4d7025e3808971b4f04413f53a1e9d108b6efe94,641d7170ed243e721a41f72b380e43ad52d68c1e..8b4b5dffbacceb81dbb05fb7e438ead3052abecc
+++ b/mdadm.c
@@@ -1100,11 -1100,12 +1100,12 @@@ int main(int argc, char *argv[]
                                int acnt;
                                ident.autof = autof;
                                do {
+                                       mddev_dev_t devlist = conf_get_devs();
                                        acnt = 0;
                                        do {
                                                rv2 = Assemble(ss, NULL, -1,
                                                               &ident,
-                                                              NULL, NULL,
+                                                              devlist, NULL,
                                                               readonly, runstop, NULL, homehost, verbose-quiet, force);
                                                if (rv2==0) {
                                                        cnt++;
                                if (cnt == 0 && rv == 0) {
                                        fprintf(stderr, Name ": No arrays found in config file or automatically\n");
                                        rv = 1;
-                               }
+                               } else if (cnt)
+                                       rv = 0;
                        } else if (cnt == 0 && rv == 0) {
                                fprintf(stderr, Name ": No arrays found in config file\n");
                                rv = 1;
                                                     export, test, homehost);
                                        continue;
                                case 'K': /* Zero superblock */
 -                                      rv |= Kill(dv->devname, force, quiet); continue;
 +                                      rv |= Kill(dv->devname, force, quiet,0);
 +                                      continue;
                                case 'Q':
                                        rv |= Query(dv->devname); continue;
                                case 'X':
diff --combined super0.c
index 5c2ee879a781a6185809b109d71308024a342bcc,8e4c568e1e360ac2e8ab1146b1bc5b06578ad8fc..b0a625bde57cd4e4a34fcc85e5d000f062105e7a
+++ b/super0.c
@@@ -623,35 -623,17 +623,35 @@@ static int init_super0(struct supertyp
        return 1;
  }
  
 +struct devinfo {
 +      int fd;
 +      char *devname;
 +      mdu_disk_info_t disk;
 +      struct devinfo *next;
 +};
  /* Add a device to the superblock being created */
 -static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo)
 +static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
 +                        int fd, char *devname)
  {
        mdp_super_t *sb = st->sb;
        mdp_disk_t *dk = &sb->disks[dinfo->number];
 +      struct devinfo *di, **dip;
  
        dk->number = dinfo->number;
        dk->major = dinfo->major;
        dk->minor = dinfo->minor;
        dk->raid_disk = dinfo->raid_disk;
        dk->state = dinfo->state;
 +
 +      dip = (struct devinfo **)&st->info;
 +      while (*dip)
 +              dip = &(*dip)->next;
 +      di = malloc(sizeof(struct devinfo));
 +      di->fd = fd;
 +      di->devname = devname;
 +      di->disk = *dinfo;
 +      di->next = NULL;
 +      *dip = di;
  }
  
  static int store_super0(struct supertype *st, int fd)
        return 0;
  }
  
 -static int write_init_super0(struct supertype *st,
 -                           mdu_disk_info_t *dinfo, char *devname)
 +#ifndef MDASSEMBLE
 +static int write_init_super0(struct supertype *st)
  {
        mdp_super_t *sb = st->sb;
 -      int fd = open(devname, O_RDWR|O_EXCL);
 -      int rv;
 +      int rv = 0;
 +      struct devinfo *di;
  
 -      if (fd < 0) {
 -              fprintf(stderr, Name ": Failed to open %s to write superblock\n", devname);
 -              return -1;
 -      }
 +      for (di = st->info ; di && ! rv ; di = di->next) {
  
 -      sb->disks[dinfo->number].state &= ~(1<<MD_DISK_FAULTY);
 +              if (di->disk.state == 1)
 +                      continue;
 +              Kill(di->devname, 0, 1, 1);
 +              Kill(di->devname, 0, 1, 1);
  
 -      sb->this_disk = sb->disks[dinfo->number];
 -      sb->sb_csum = calc_sb0_csum(sb);
 -      rv = store_super0(st, fd);
 +              sb->disks[di->disk.number].state &= ~(1<<MD_DISK_FAULTY);
  
 -      if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
 -              rv = st->ss->write_bitmap(st, fd);
 +              sb->this_disk = sb->disks[di->disk.number];
 +              sb->sb_csum = calc_sb0_csum(sb);
 +              rv = store_super0(st, di->fd);
  
 -      close(fd);
 -      if (rv)
 -              fprintf(stderr, Name ": failed to write superblock to %s\n", devname);
 +              if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
 +                      rv = st->ss->write_bitmap(st, di->fd);
 +
 +              if (rv)
 +                      fprintf(stderr,
 +                              Name ": failed to write superblock to %s\n",
 +                              di->devname);
 +              close(di->fd);
 +              di->fd = -1;
 +      }
        return rv;
  }
 +#endif
  
  static int compare_super0(struct supertype *st, struct supertype *tst)
  {
@@@ -837,7 -812,6 +837,7 @@@ static int load_super0(struct supertyp
                st->ss = &super0;
                st->minor_version = super->minor_version;
                st->max_devs = MD_SB_DISKS;
 +              st->info = NULL;
        }
  
        /* Now check on the bitmap superblock */
@@@ -870,18 -844,20 +870,21 @@@ static struct supertype *match_metadata
        if (!st) return st;
  
        st->ss = &super0;
 +      st->info = NULL;
        st->minor_version = 90;
        st->max_devs = MD_SB_DISKS;
        st->sb = NULL;
        if (strcmp(arg, "0") == 0 ||
            strcmp(arg, "0.90") == 0 ||
-           strcmp(arg, "0.91") == 0 ||
            strcmp(arg, "default") == 0 ||
            strcmp(arg, "") == 0 /* no metadata */
                )
                return st;
  
+       st->minor_version = 91; /* reshape in progress */
+       if (strcmp(arg, "0.91") == 0) /* For dup_super support */
+               return st;
        st->minor_version = 9; /* flag for 'byte-swapped' */
        if (strcmp(arg, "0.swap")==0 ||
            strcmp(arg, "0.9") == 0) /* For dup_super support */
@@@ -1018,43 -994,6 +1021,43 @@@ static void free_super0(struct supertyp
        st->sb = NULL;
  }
  
 +static int validate_geometry0(struct supertype *st, int level,
 +                            int layout, int raiddisks,
 +                            int chunk, unsigned long long size,
 +                            char *subdev, unsigned long long *freesize)
 +{
 +      unsigned long long ldsize;
 +      int fd;
 +
 +      if (level == LEVEL_CONTAINER)
 +              return 0;
 +      if (raiddisks > MD_SB_DISKS)
 +              return 0;
 +      if (size > (0x7fffffffULL<<10))
 +              return 0;
 +      if (!subdev)
 +              return 1;
 +
 +      fd = open(subdev, O_RDONLY|O_EXCL, 0);
 +      if (fd < 0) {
 +              fprintf(stderr, Name ": Cannot open %s: %s\n",
 +                      subdev, strerror(errno));
 +              return 0;
 +      }
 +      if (!get_dev_size(fd, subdev, &ldsize)) {
 +              close(fd);
 +              return 0;
 +      }
 +      close(fd);
 +
 +      if (ldsize < MD_RESERVED_SECTORS * 512)
 +              return 0;
 +      if (size > (0x7fffffffULL<<10))
 +              return 0;
 +      *freesize = MD_NEW_SIZE_SECTORS(ldsize >> 9);
 +      return 1;
 +}
 +
  struct superswitch super0 = {
  #ifndef MDASSEMBLE
        .examine_super = examine_super0,
        .detail_super = detail_super0,
        .brief_detail_super = brief_detail_super0,
        .export_detail_super = export_detail_super0,
 +      .write_init_super = write_init_super0,
  #endif
        .match_home = match_home0,
        .uuid_from_super = uuid_from_super0,
        .init_super = init_super0,
        .add_to_super = add_to_super0,
        .store_super = store_super0,
 -      .write_init_super = write_init_super0,
        .compare_super = compare_super0,
        .load_super = load_super0,
        .match_metadata_desc = match_metadata_desc0,
        .locate_bitmap = locate_bitmap0,
        .write_bitmap = write_bitmap0,
        .free_super = free_super0,
 +      .validate_geometry = validate_geometry0,
        .major = 0,
        .swapuuid = 0,
  };