Merge branch 'master' into devel-3.0
authorNeilBrown <neilb@suse.de>
Mon, 11 May 2009 06:05:41 +0000 (16:05 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 11 May 2009 06:05:41 +0000 (16:05 +1000)
Conflicts:
Build.c
mdadm.c
mdadm.h
super1.c

1  2 
Build.c
Makefile
Manage.c
bitmap.c
mdadm.c
mdadm.h
super1.c

diff --cc Build.c
+++ b/Build.c
  #define START_MD              _IO (MD_MAJOR, 2)
  #define STOP_MD               _IO (MD_MAJOR, 3)
  
 -int Build(char *mddev, int mdfd, int chunk, int level, int layout,
 -        int raiddisks,
 -        mddev_dev_t devlist, int assume_clean,
 -        char *bitmap_file, int bitmap_chunk, int write_behind, int delay,
 -        int verbose, unsigned long long size)
 +int Build(char *mddev, int chunk, int level, int layout,
 +        int raiddisks, mddev_dev_t devlist, int assume_clean,
 +        char *bitmap_file, int bitmap_chunk, int write_behind,
-         int delay, int verbose, int autof)
++        int delay, int verbose, int autof, unsigned long long size)
  {
        /* Build a linear or raid0 arrays without superblocks
         * We cannot really do any checks, we just do it.
        int subdevs = 0, missing_disks = 0;
        mddev_dev_t dv;
        int bitmap_fd;
-       unsigned long long size = ~0ULL;
        unsigned long long bitmapsize;
 +      int mdfd;
 +      char chosen_name[1024];
 +      int uuid[4] = {0,0,0,0};
 +      struct map_ent *map = NULL;
  
        /* scan all devices, make sure they really are block devices */
        for (dv = devlist; dv; dv=dv->next) {
diff --cc Makefile
+++ b/Makefile
@@@ -127,18 -111,14 +127,18 @@@ mdadm.tcc : $(SRCS) mdadm.
  
  mdadm.klibc : $(SRCS) mdadm.h
        rm -f $(OBJS) 
-       gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS)
+       $(CC) -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS)
  
  mdadm.Os : $(SRCS) mdadm.h
-       gcc -o mdadm.Os $(CFLAGS)  -DHAVE_STDINT_H -Os $(SRCS)
+       $(CC) -o mdadm.Os $(CFLAGS)  -DHAVE_STDINT_H -Os $(SRCS)
  
  mdadm.O2 : $(SRCS) mdadm.h
-       gcc -o mdadm.O2 $(CFLAGS)  -DHAVE_STDINT_H -O2 $(SRCS)
+       $(CC) -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
  
diff --cc Manage.c
Simple merge
diff --cc bitmap.c
Simple merge
diff --cc mdadm.c
+++ b/mdadm.c
@@@ -1199,10 -1160,10 +1200,10 @@@ int main(int argc, char *argv[]
                                break;
                        }
                }
 -              rv = Build(devlist->devname, mdfd, chunk, level, layout,
 +              rv = Build(devlist->devname, chunk, level, layout,
                           raiddisks, devlist->next, assume_clean,
 -                         bitmap_file, bitmap_chunk, write_behind, delay,
 -                         verbose-quiet, size);
 +                         bitmap_file, bitmap_chunk, write_behind,
-                          delay, verbose-quiet, autof);
++                         delay, verbose-quiet, autof, size);
                break;
        case CREATE:
                if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
diff --cc mdadm.h
+++ b/mdadm.h
@@@ -724,16 -437,17 +724,16 @@@ extern int Assemble(struct supertype *s
                    mddev_ident_t ident,
                    mddev_dev_t devlist, char *backup_file,
                    int readonly, int runstop,
 -                  char *update, char *homehost,
 +                  char *update, char *homehost, int require_homehost,
                    int verbose, int force);
  
 -extern int Build(char *mddev, int mdfd, int chunk, int level, int layout,
 -               int raiddisks,
 -               mddev_dev_t devlist, int assume_clean,
 +extern int Build(char *mddev, int chunk, int level, int layout,
 +               int raiddisks, mddev_dev_t devlist, int assume_clean,
                 char *bitmap_file, int bitmap_chunk, int write_behind,
-                int delay, int verbose, int autof);
 -               int delay, int verbose, unsigned long long size);
++               int delay, int verbose, int autof, unsigned long long size);
  
  
 -extern int Create(struct supertype *st, char *mddev, int mdfd,
 +extern int Create(struct supertype *st, char *mddev,
                  int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
                  char *name, char *homehost, int *uuid,
                  int subdevs, mddev_dev_t devlist,
diff --cc super1.c
+++ b/super1.c
@@@ -1008,121 -895,109 +1004,121 @@@ static int write_init_super1(struct sup
        unsigned long long dsize, array_size;
        long long sb_offset;
  
 +      for (di = st->info; di && ! rv ; di = di->next) {
 +              if (di->disk.state == 1)
 +                      continue;
 +              if (di->fd < 0)
 +                      continue;
  
 -      if (fd < 0) {
 -              fprintf(stderr, Name ": Failed to open %s to write superblock\n",
 -                      devname);
 -              return -1;
 -      }
 +              Kill(di->devname, 0, 1, 1);
 +              Kill(di->devname, 0, 1, 1);
  
 -      sb->dev_number = __cpu_to_le32(dinfo->number);
 -      if (dinfo->state & (1<<MD_DISK_WRITEMOSTLY))
 -              sb->devflags |= __cpu_to_le32(WriteMostly1);
 +              sb->dev_number = __cpu_to_le32(di->disk.number);
 +              if (di->disk.state & (1<<MD_DISK_WRITEMOSTLY))
 +                      sb->devflags |= __cpu_to_le32(WriteMostly1);
  
 -      if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
 -          read(rfd, sb->device_uuid, 16) != 16) {
 -              __u32 r[4] = {random(), random(), random(), random()};
 -              memcpy(sb->device_uuid, r, 16);
 -      }
 -      
 -      if (rfd >= 0) close(rfd);
 -      sb->events = 0;
 -
 -      refst =*st;
 -      refst.sb = NULL;
 -      if (load_super1(&refst, fd, NULL)==0) {
 -              struct mdp_superblock_1 *refsb = refst.sb;
 -
 -              memcpy(sb->device_uuid, refsb->device_uuid, 16);
 -              if (memcmp(sb->set_uuid, refsb->set_uuid, 16)==0) {
 -                      /* same array, so preserve events and dev_number */
 -                      sb->events = refsb->events;
 -                      /* bugs in 2.6.17 and earlier mean the dev_number
 -                       * chosen in Manage must be preserved
 -                       */
 -                      if (get_linux_version() >= 2006018)
 -                              sb->dev_number = refsb->dev_number;
 +              if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
 +                  read(rfd, sb->device_uuid, 16) != 16) {
-                       *(__u32*)(sb->device_uuid) = random();
-                       *(__u32*)(sb->device_uuid+4) = random();
-                       *(__u32*)(sb->device_uuid+8) = random();
-                       *(__u32*)(sb->device_uuid+12) = random();
++                      __u32 r[4] = {random(), random(), random(), random()};
++                      memcpy(sb->device_uuid, r, 16);
 +              }
-               if (rfd >= 0) close(rfd);
++              if (rfd >= 0)
++                      close(rfd);
++
 +              sb->events = 0;
 +
 +              refst =*st;
 +              refst.sb = NULL;
 +              if (load_super1(&refst, di->fd, NULL)==0) {
 +                      struct mdp_superblock_1 *refsb = refst.sb;
 +
 +                      memcpy(sb->device_uuid, refsb->device_uuid, 16);
 +                      if (memcmp(sb->set_uuid, refsb->set_uuid, 16)==0) {
 +                              /* same array, so preserve events and
 +                               * dev_number */
 +                              sb->events = refsb->events;
 +                              /* bugs in 2.6.17 and earlier mean the
 +                               * dev_number chosen in Manage must be preserved
 +                               */
 +                              if (get_linux_version() >= 2006018)
 +                                      sb->dev_number = refsb->dev_number;
 +                      }
 +                      free(refsb);
                }
 -              free(refsb);
 -      }
  
 -      if (!get_dev_size(fd, NULL, &dsize))
 -              return 1;
 -      dsize >>= 9;
 +              if (!get_dev_size(di->fd, NULL, &dsize))
 +                      return 1;
 +              dsize >>= 9;
  
 -      if (dsize < 24) {
 -              close(fd);
 -              return 2;
 -      }
 +              if (dsize < 24) {
 +                      close(di->fd);
 +                      return 2;
 +              }
  
  
 -      /*
 -       * Calculate the position of the superblock.
 -       * It is always aligned to a 4K boundary and
 -       * depending on minor_version, it can be:
 -       * 0: At least 8K, but less than 12K, from end of device
 -       * 1: At start of device
 -       * 2: 4K from start of device.
 -       * Depending on the array size, we might leave extra space
 -       * for a bitmap.
 -       */
 -      array_size = __le64_to_cpu(sb->size);
 -      /* work out how much space we left for a bitmap */
 -      bm_space = choose_bm_space(array_size);
 -
 -      switch(st->minor_version) {
 -      case 0:
 -              sb_offset = dsize;
 -              sb_offset -= 8*2;
 -              sb_offset &= ~(4*2-1);
 -              sb->super_offset = __cpu_to_le64(sb_offset);
 -              sb->data_offset = __cpu_to_le64(0);
 +              /*
 +               * Calculate the position of the superblock.
 +               * It is always aligned to a 4K boundary and
 +               * depending on minor_version, it can be:
 +               * 0: At least 8K, but less than 12K, from end of device
 +               * 1: At start of device
 +               * 2: 4K from start of device.
 +               * Depending on the array size, we might leave extra space
 +               * for a bitmap.
 +               */
 +              array_size = __le64_to_cpu(sb->size);
 +              /* work out how much space we left for a bitmap */
 +              bm_space = choose_bm_space(array_size);
 +
 +              switch(st->minor_version) {
 +              case 0:
 +                      sb_offset = dsize;
 +                      sb_offset -= 8*2;
 +                      sb_offset &= ~(4*2-1);
 +                      sb->super_offset = __cpu_to_le64(sb_offset);
 +                      sb->data_offset = __cpu_to_le64(0);
                if (sb_offset - bm_space < array_size)
                        bm_space = sb_offset - array_size;
 -              sb->data_size = __cpu_to_le64(sb_offset - bm_space);
 -              break;
 -      case 1:
 -              sb->super_offset = __cpu_to_le64(0);
 -              if (4*2 + bm_space + __le64_to_cpu(sb->size) > dsize)
 -                      bm_space = dsize - __le64_to_cpu(sb->size) - 4*2;
 -              sb->data_offset = __cpu_to_le64(bm_space + 4*2);
 -              sb->data_size = __cpu_to_le64(dsize - bm_space - 4*2);
 -              break;
 -      case 2:
 -              sb_offset = 4*2;
 -              sb->super_offset = __cpu_to_le64(4*2);
 -              if (4*2 + 4*2 + bm_space + __le64_to_cpu(sb->size) > dsize)
 -                      bm_space = dsize - __le64_to_cpu(sb->size) - 4*2 - 4*2;
 -              sb->data_offset = __cpu_to_le64(4*2 + 4*2 + bm_space);
 -              sb->data_size = __cpu_to_le64(dsize - 4*2 - 4*2 - bm_space );
 -              break;
 -      default:
 -              return -EINVAL;
 -      }
 +                      sb->data_size = __cpu_to_le64(sb_offset - bm_space);
 +                      break;
 +              case 1:
 +                      sb->super_offset = __cpu_to_le64(0);
 +                      if (4*2 + bm_space + __le64_to_cpu(sb->size) > dsize)
 +                              bm_space = dsize - __le64_to_cpu(sb->size) -4*2;
 +                      sb->data_offset = __cpu_to_le64(bm_space + 4*2);
 +                      sb->data_size = __cpu_to_le64(dsize - bm_space - 4*2);
 +                      break;
 +              case 2:
 +                      sb_offset = 4*2;
 +                      sb->super_offset = __cpu_to_le64(4*2);
 +                      if (4*2 + 4*2 + bm_space + __le64_to_cpu(sb->size)
 +                          > dsize)
 +                              bm_space = dsize - __le64_to_cpu(sb->size)
 +                                      - 4*2 - 4*2;
 +                      sb->data_offset = __cpu_to_le64(4*2 + 4*2 + bm_space);
 +                      sb->data_size = __cpu_to_le64(dsize - 4*2 - 4*2
 +                                                    - bm_space );
 +                      break;
 +              default:
 +                      return -EINVAL;
 +              }
  
  
 -      sb->sb_csum = calc_sb_1_csum(sb);
 -      rv = store_super1(st, fd);
 -      if (rv)
 -              fprintf(stderr, Name ": failed to write superblock to %s\n", devname);
 +              sb->sb_csum = calc_sb_1_csum(sb);
 +              rv = store_super1(st, di->fd);
 +              if (rv)
 +                      fprintf(stderr,
 +                              Name ": failed to write superblock to %s\n",
 +                              di->devname);
  
 -      if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1))
 -              rv = st->ss->write_bitmap(st, fd);
 -      close(fd);
 +              if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1))
 +                      rv = st->ss->write_bitmap(st, di->fd);
 +              close(di->fd);
 +              di->fd = -1;
 +      }
        return rv;
  }
 +#endif
  
  static int compare_super1(struct supertype *st, struct supertype *tst)
  {