~ubuntu-branches/ubuntu/quantal/mdadm/quantal-proposed

« back to all changes in this revision

Viewing changes to Assemble.c

  • Committer: Package Import Robot
  • Author(s): Scott James Remnant
  • Date: 2007-07-11 10:31:39 UTC
  • mfrom: (1.1.6)
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20070711103139-ih7oxwxsal9ndbej
Tags: upstream-2.6.2
ImportĀ upstreamĀ versionĀ 2.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
         *    START_ARRAY
112
112
         *
113
113
         */
 
114
        int clean = 0;
114
115
        int must_close = 0;
115
116
        int old_linux = 0;
116
117
        int vers = 0; /* Keep gcc quite - it really is initialised */
135
136
        int chosen_drive;
136
137
        int change = 0;
137
138
        int inargv = 0;
 
139
        int bitmap_done;
138
140
        int start_partial_ok = (runstop >= 0) && (force || devlist==NULL || mdfd < 0);
139
141
        unsigned int num_devs;
140
142
        mddev_dev_t tmpdev;
412
414
        }
413
415
 
414
416
        /* Ok, no bad inconsistancy, we can try updating etc */
 
417
        bitmap_done = 0;
415
418
        for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) {
416
419
                char *devname = tmpdev->devname;
417
420
                struct stat stb;
468
471
                                close(dfd);
469
472
 
470
473
                        if (strcmp(update, "uuid")==0 &&
471
 
                            ident->bitmap_fd)
472
 
                                if (bitmap_update_uuid(ident->bitmap_fd, info.uuid) != 0)
473
 
                                        fprintf(stderr, Name ": Could not update uuid on %s.\n",
474
 
                                                devname);
 
474
                            ident->bitmap_fd >= 0 && !bitmap_done) {
 
475
                                if (bitmap_update_uuid(ident->bitmap_fd, info.uuid, st->ss->swapuuid) != 0)
 
476
                                        fprintf(stderr, Name ": Could not update uuid on external bitmap.\n");
 
477
                                else
 
478
                                        bitmap_done = 1;
 
479
                        }
475
480
                } else
476
481
#endif
477
482
                {
583
588
        }
584
589
 
585
590
        st->ss->getinfo_super(&info, first_super);
 
591
        clean = info.array.state & 1;
586
592
 
587
593
        /* now we have some devices that might be suitable.
588
594
         * I wonder how many
617
623
                }
618
624
        }
619
625
        while (force && !enough(info.array.level, info.array.raid_disks,
620
 
                                info.array.layout,
 
626
                                info.array.layout, 1,
621
627
                                avail, okcnt)) {
622
628
                /* Choose the newest best drive which is
623
629
                 * not up-to-date, update the superblock
624
630
                 * and add it.
625
631
                 */
626
632
                int fd;
 
633
                long long current_events;
627
634
                chosen_drive = -1;
628
635
                for (i=0; i<info.array.raid_disks && i < bestcnt; i++) {
629
636
                        int j = best[i];
636
643
                }
637
644
                if (chosen_drive < 0)
638
645
                        break;
 
646
                current_events = devices[chosen_drive].events;
 
647
        add_another:
639
648
                if (verbose >= 0)
640
649
                        fprintf(stderr, Name ": forcing event count in %s(%d) from %d upto %d\n",
641
650
                                devices[chosen_drive].devname, devices[chosen_drive].raid_disk,
656
665
                        continue;
657
666
                }
658
667
                info.events = devices[most_recent].events;
659
 
                st->ss->update_super(&info, super, "force", devices[chosen_drive].devname, verbose, 0, NULL);
 
668
                st->ss->update_super(&info, super, "force-one",
 
669
                                     devices[chosen_drive].devname, verbose,
 
670
                                     0, NULL);
660
671
 
661
672
                if (st->ss->store_super(st, fd, super)) {
662
673
                        close(fd);
672
683
                avail[chosen_drive] = 1;
673
684
                okcnt++;
674
685
                free(super);
 
686
 
 
687
                /* If there are any other drives of the same vintage,
 
688
                 * add them in as well.  We can't lose and we might gain
 
689
                 */
 
690
                for (i=0; i<info.array.raid_disks && i < bestcnt ; i++) {
 
691
                        int j = best[i];
 
692
                        if (j >= 0 &&
 
693
                            !devices[j].uptodate &&
 
694
                            devices[j].events > 0 &&
 
695
                            devices[j].events == current_events) {
 
696
                                chosen_drive = j;
 
697
                                goto add_another;
 
698
                        }
 
699
                }
675
700
        }
676
701
 
677
702
        /* Now we want to look at the superblock which the kernel will base things on
752
777
                }
753
778
#endif
754
779
        }
755
 
        if (force && okcnt == info.array.raid_disks-1) {
756
 
                /* FIXME check event count */
757
 
                change += st->ss->update_super(&info, super, "force",
758
 
                                        devices[chosen_drive].devname, verbose, 0, NULL);
 
780
        if (force && !clean &&
 
781
            !enough(info.array.level, info.array.raid_disks,
 
782
                    info.array.layout, clean,
 
783
                    avail, okcnt)) {
 
784
                change += st->ss->update_super(&info, super, "force-array",
 
785
                                        devices[chosen_drive].devname, verbose,
 
786
                                               0, NULL);
 
787
                clean = 1;
759
788
        }
760
789
 
761
790
        if (change) {
892
921
                
893
922
                if (runstop == 1 ||
894
923
                    (runstop <= 0 &&
895
 
                     ( enough(info.array.level, info.array.raid_disks, info.array.layout, avail, okcnt) &&
 
924
                     ( enough(info.array.level, info.array.raid_disks,
 
925
                              info.array.layout, clean, avail, okcnt) &&
896
926
                       (okcnt >= req_cnt || start_partial_ok)
897
927
                             ))) {
898
928
                        if (ioctl(mdfd, RUN_ARRAY, NULL)==0) {
921
951
                                        while (usecs < 1000) {
922
952
                                                mdfd = open(mddev, O_RDONLY);
923
953
                                                if (mdfd >= 0) {
924
 
                                                        unsigned long size;
925
 
                                                        if (ioctl(mdfd, BLKGETSIZE, &size) == 0 &&
 
954
                                                        unsigned long long size;
 
955
                                                        if (get_dev_size(mdfd, NULL, &size) &&
926
956
                                                            size > 0)
927
957
                                                                break;
928
958
                                                        close(mdfd);
935
965
                        }
936
966
                        fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n",
937
967
                                mddev, strerror(errno));
 
968
 
 
969
                        if (!enough(info.array.level, info.array.raid_disks,
 
970
                                    info.array.layout, 1, avail, okcnt))
 
971
                                fprintf(stderr, Name ": Not enough devices to "
 
972
                                        "start the array.\n");
 
973
                        else if (!enough(info.array.level,
 
974
                                         info.array.raid_disks,
 
975
                                         info.array.layout, clean,
 
976
                                         avail, okcnt))
 
977
                                fprintf(stderr, Name ": Not enough devices to "
 
978
                                        "start the array while not clean "
 
979
                                        "- consider --force.\n");
 
980
 
938
981
                        if (must_close) close(mdfd);
939
982
                        return 1;
940
983
                }
947
990
                        if (must_close) close(mdfd);
948
991
                        return 0;
949
992
                }
950
 
                if (verbose >= 0) {
 
993
                if (verbose >= -1) {
951
994
                        fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s");
952
995
                        if (sparecnt)
953
996
                                fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
954
 
                        if (!enough(info.array.level, info.array.raid_disks, info.array.layout, avail, okcnt))
 
997
                        if (!enough(info.array.level, info.array.raid_disks,
 
998
                                    info.array.layout, 1, avail, okcnt))
955
999
                                fprintf(stderr, " - not enough to start the array.\n");
 
1000
                        else if (!enough(info.array.level,
 
1001
                                         info.array.raid_disks,
 
1002
                                         info.array.layout, clean,
 
1003
                                         avail, okcnt))
 
1004
                                fprintf(stderr, " - not enough to start the "
 
1005
                                        "array while not clean - consider "
 
1006
                                        "--force.\n");
956
1007
                        else {
957
1008
                                if (req_cnt == info.array.raid_disks)
958
1009
                                        fprintf(stderr, " - need all %d to start it", req_cnt);