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

« back to all changes in this revision

Viewing changes to Incremental.c

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich
  • Date: 2008-07-15 14:49:26 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: package-import@ubuntu.com-20080715144926-v5s9ta0z49ghkt71
Tags: upstream-2.6.7
ImportĀ upstreamĀ versionĀ 2.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
static int count_active(struct supertype *st, int mdfd, char **availp,
34
34
                        struct mdinfo *info);
35
 
static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
 
35
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
36
36
                        int number, __u64 events, int verbose,
37
37
                        char *array_name);
38
38
 
74
74
         *   start the array (auto-readonly).
75
75
         */
76
76
        struct stat stb;
77
 
        void *super, *super2;
78
77
        struct mdinfo info, info2;
79
78
        struct mddev_ident_s *array_list, *match;
80
79
        char chosen_name[1024];
134
133
                close(dfd);
135
134
                return 1;
136
135
        }
137
 
        if (st->ss->load_super(st, dfd, &super, NULL)) {
 
136
        if (st->ss->load_super(st, dfd, NULL)) {
138
137
                if (verbose >= 0)
139
138
                        fprintf(stderr, Name ": no RAID superblock on %s.\n",
140
139
                                devname);
141
140
                close(dfd);
142
141
                return 1;
143
142
        }
144
 
        st->ss->getinfo_super(&info, super);
 
143
        st->ss->getinfo_super(st, &info);
145
144
        close (dfd);
146
145
 
147
146
        /* 3/ Check if there is a match in mdadm.conf */
207
206
        /* 3a/ if not, check for homehost match.  If no match, reject. */
208
207
        if (!match) {
209
208
                if (homehost == NULL ||
210
 
                    st->ss->match_home(super, homehost) == 0) {
 
209
                    st->ss->match_home(st, homehost) == 0) {
211
210
                        if (verbose >= 0)
212
211
                                fprintf(stderr, Name
213
212
              ": not found in mdadm.conf and not identified by homehost.\n");
247
246
 
248
247
                if (devnum < 0) {
249
248
                        /* Haven't found anything yet, choose something free */
250
 
                        /* There is similar code in mdopen.c - should unify */
251
 
                        for (devnum = 127 ; devnum != 128 ;
252
 
                             devnum = devnum ? devnum-1 : (1<<22)-1) {
253
 
                                if (mddev_busy(use_partitions ?
254
 
                                               (-1-devnum) : devnum))
255
 
                                        break;
256
 
                        }
257
 
                        if (devnum == 128) {
 
249
                        devnum = find_free_devnum(use_partitions);
 
250
 
 
251
                        if (devnum == NoMdDev) {
258
252
                                fprintf(stderr, Name
259
253
                                        ": No spare md devices!!\n");
260
254
                                return 2;
261
255
                        }
262
 
                }
263
 
                devnum = use_partitions ? (-1-devnum) : devnum;
 
256
                } else
 
257
                        devnum = use_partitions ? (-1-devnum) : devnum;
264
258
        }
265
259
        mdfd = open_mddev_devnum(match ? match->devname : NULL,
266
260
                                 devnum,
267
261
                                 info.name,
268
 
                                 chosen_name);
 
262
                                 chosen_name, autof >> 3);
269
263
        if (mdfd < 0) {
270
264
                fprintf(stderr, Name ": failed to open %s: %s.\n",
271
265
                        chosen_name, strerror(errno));
280
274
                mdu_array_info_t ainf;
281
275
                mdu_disk_info_t disk;
282
276
                char md[20];
283
 
                struct sysarray *sra;
 
277
                struct mdinfo *sra;
284
278
 
285
279
                memset(&ainf, 0, sizeof(ainf));
286
280
                ainf.major_version = st->ss->major;
307
301
                        return 2;
308
302
                }
309
303
                sra = sysfs_read(mdfd, devnum, GET_DEVS);
310
 
                if (!sra || !sra->devs || sra->devs->role >= 0) {
 
304
                if (!sra || !sra->devs || sra->devs->disk.raid_disk >= 0) {
311
305
                        /* It really should be 'none' - must be old buggy
312
306
                         * kernel, and mdadm -I may not be able to complete.
313
307
                         * So reject it.
329
323
                int dfd2;
330
324
                mdu_disk_info_t disk;
331
325
                int err;
332
 
                struct sysarray *sra;
 
326
                struct mdinfo *sra;
 
327
                struct supertype *st2;
333
328
                sra = sysfs_read(mdfd, devnum, (GET_VERSION | GET_DEVS |
334
329
                                                GET_STATE));
335
 
                if (sra->major_version != st->ss->major ||
336
 
                    sra->minor_version != st->minor_version) {
 
330
 
 
331
                if (sra->array.major_version != st->ss->major ||
 
332
                    sra->array.minor_version != st->minor_version) {
337
333
                        if (verbose >= 0)
338
334
                                fprintf(stderr, Name
339
335
              ": %s has different metadata to chosen array %s %d.%d %d.%d.\n",
340
336
                                        devname, chosen_name,
341
 
                                        sra->major_version, sra->minor_version,
 
337
                                        sra->array.major_version,
 
338
                                        sra->array.minor_version,
342
339
                                        st->ss->major, st->minor_version);
343
340
                        close(mdfd);
344
341
                        return 1;
345
342
                }
346
 
                sprintf(dn, "%d:%d", sra->devs->major, sra->devs->minor);
 
343
                sprintf(dn, "%d:%d", sra->devs->disk.major,
 
344
                        sra->devs->disk.minor);
347
345
                dfd2 = dev_open(dn, O_RDONLY);
348
 
                if (st->ss->load_super(st, dfd2,&super2, NULL)) {
 
346
                st2 = dup_super(st);
 
347
                if (st2->ss->load_super(st2, dfd2, NULL)) {
349
348
                        fprintf(stderr, Name
350
349
                                ": Strange error loading metadata for %s.\n",
351
350
                                chosen_name);
354
353
                        return 2;
355
354
                }
356
355
                close(dfd2);
357
 
                st->ss->getinfo_super(&info2, super2);
 
356
                st2->ss->getinfo_super(st2, &info2);
 
357
                st2->ss->free_super(st2);
358
358
                if (info.array.level != info2.array.level ||
359
359
                    memcmp(info.uuid, info2.uuid, 16) != 0 ||
360
360
                    info.array.raid_disks != info2.array.raid_disks) {
424
424
        }
425
425
}
426
426
        if (runstop > 0 || active_disks >= info.array.working_disks) {
427
 
                struct sysarray *sra;
 
427
                struct mdinfo *sra;
428
428
                /* Let's try to start it */
429
429
                if (match && match->bitmap_file) {
430
430
                        int bmfd = open(match->bitmap_file, O_RDWR);
474
474
        return rv;
475
475
}
476
476
 
477
 
static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
 
477
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
478
478
                        int number, __u64 events, int verbose,
479
479
                        char *array_name)
480
480
{
481
 
        /* Find an device attached to this array with a disk.number of number
 
481
        /* Find a device attached to this array with a disk.number of number
482
482
         * and events less than the passed events, and remove the device.
483
483
         */
484
 
        struct sysdev *d;
 
484
        struct mdinfo *d;
485
485
        mdu_array_info_t ra;
486
486
 
487
487
        if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
491
491
        for (d = sra->devs; d ; d = d->next) {
492
492
                char dn[10];
493
493
                int dfd;
494
 
                void *super;
495
494
                struct mdinfo info;
496
 
                sprintf(dn, "%d:%d", d->major, d->minor);
 
495
                sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
497
496
                dfd = dev_open(dn, O_RDONLY);
498
497
                if (dfd < 0)
499
498
                        continue;
500
 
                if (st->ss->load_super(st, dfd, &super, NULL)) {
 
499
                if (st->ss->load_super(st, dfd, NULL)) {
501
500
                        close(dfd);
502
501
                        continue;
503
502
                }
504
 
                st->ss->getinfo_super(&info, super);
505
 
                free(super);
 
503
                st->ss->getinfo_super(st, &info);
 
504
                st->ss->free_super(st);
506
505
                close(dfd);
507
506
 
508
507
                if (info.disk.number != number ||
509
508
                    info.events >= events)
510
509
                        continue;
511
510
 
512
 
                if (d->role > -1)
 
511
                if (d->disk.raid_disk > -1)
513
512
                        sysfs_set_str(sra, d, "slot", "none");
514
513
                if (sysfs_set_str(sra, d, "state", "remove") == 0)
515
514
                        if (verbose >= 0)
516
515
                                fprintf(stderr, Name
517
516
                                        ": removing old device %s from %s\n",
518
 
                                        d->name+4, array_name);
 
517
                                        d->sys_name+4, array_name);
519
518
        }
520
519
}
521
520
 
523
522
                        struct mdinfo *bestinfo)
524
523
{
525
524
        /* count how many devices in sra think they are active */
526
 
        struct sysdev *d;
 
525
        struct mdinfo *d;
527
526
        int cnt = 0, cnt1 = 0;
528
527
        __u64 max_events = 0;
529
 
        void *best_super = NULL;
530
 
        struct sysarray *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
 
528
        struct mdinfo *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
531
529
        char *avail = NULL;
532
530
 
533
531
        for (d = sra->devs ; d ; d = d->next) {
534
532
                char dn[30];
535
533
                int dfd;
536
 
                void *super;
537
534
                int ok;
538
535
                struct mdinfo info;
539
536
 
540
 
                sprintf(dn, "%d:%d", d->major, d->minor);
 
537
                sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
541
538
                dfd = dev_open(dn, O_RDONLY);
542
539
                if (dfd < 0)
543
540
                        continue;
544
 
                ok =  st->ss->load_super(st, dfd, &super, NULL);
 
541
                ok =  st->ss->load_super(st, dfd, NULL);
545
542
                close(dfd);
546
543
                if (ok != 0)
547
544
                        continue;
548
 
                st->ss->getinfo_super(&info, super);
 
545
                st->ss->getinfo_super(st, &info);
549
546
                if (info.disk.state & (1<<MD_DISK_SYNC))
550
547
                {
551
548
                        if (avail == NULL) {
556
553
                                cnt++;
557
554
                                max_events = info.events;
558
555
                                avail[info.disk.raid_disk] = 2;
559
 
                                best_super = super; super = NULL;
 
556
                                st->ss->getinfo_super(st, bestinfo);
560
557
                        } else if (info.events == max_events) {
561
558
                                cnt++;
562
559
                                avail[info.disk.raid_disk] = 2;
574
571
                                        if (avail[i])
575
572
                                                avail[i]--;
576
573
                                avail[info.disk.raid_disk] = 2;
577
 
                                free(best_super);
578
 
                                best_super = super;
579
 
                                super = NULL;
 
574
                                st->ss->getinfo_super(st, bestinfo);
580
575
                        } else { /* info.events much bigger */
581
576
                                cnt = 1; cnt1 = 0;
582
577
                                memset(avail, 0, info.disk.raid_disk);
583
578
                                max_events = info.events;
584
 
                                free(best_super);
585
 
                                best_super = super;
586
 
                                super = NULL;
 
579
                                st->ss->getinfo_super(st, bestinfo);
587
580
                        }
588
581
                }
589
 
                if (super)
590
 
                        free(super);
591
 
        }
592
 
        if (best_super) {
593
 
                st->ss->getinfo_super(bestinfo,best_super);
594
 
                free(best_super);
 
582
                st->ss->free_super(st);
595
583
        }
596
584
        return cnt + cnt1;
597
585
}
604
592
        int mdp = get_mdp_major();
605
593
 
606
594
        for (md = mdstat ; md ; md = md->next) {
607
 
                struct sysarray *sra = sysfs_read(-1, md->devnum, GET_DEVS);
608
 
                struct sysdev *sd;
 
595
                struct mdinfo *sra = sysfs_read(-1, md->devnum, GET_DEVS);
 
596
                struct mdinfo *sd;
609
597
 
610
598
                for (sd = sra->devs ; sd ; sd = sd->next) {
611
599
                        char dn[30];
613
601
                        int ok;
614
602
                        struct supertype *st;
615
603
                        char *path;
616
 
                        void *super;
617
604
                        struct mdinfo info;
618
605
 
619
 
                        sprintf(dn, "%d:%d", sd->major, sd->minor);
 
606
                        sprintf(dn, "%d:%d", sd->disk.major, sd->disk.minor);
620
607
                        dfd = dev_open(dn, O_RDONLY);
621
608
                        if (dfd < 0)
622
609
                                continue;
624
611
                        if ( st == NULL)
625
612
                                ok = -1;
626
613
                        else
627
 
                                ok = st->ss->load_super(st, dfd, &super, NULL);
 
614
                                ok = st->ss->load_super(st, dfd, NULL);
628
615
                        close(dfd);
629
616
                        if (ok != 0)
630
617
                                continue;
631
 
                        st->ss->getinfo_super(&info, super);
 
618
                        st->ss->getinfo_super(st, &info);
632
619
                        if (md->devnum > 0)
633
620
                                path = map_dev(MD_MAJOR, md->devnum, 0);
634
621
                        else
636
623
                        map_add(&map, md->devnum, st->ss->major,
637
624
                                st->minor_version,
638
625
                                info.uuid, path ? : "/unknown");
639
 
                        free(super);
 
626
                        st->ss->free_super(st);
640
627
                        break;
641
628
                }
642
629
        }
664
651
                char path[1024];
665
652
                mdu_array_info_t array;
666
653
                mdu_bitmap_file_t bmf;
667
 
                struct sysarray *sra;
668
 
                int mdfd = open_mddev_devnum(me->path, me->devnum, NULL, path);
 
654
                struct mdinfo *sra;
 
655
                int mdfd = open_mddev_devnum(me->path, me->devnum,
 
656
                                             NULL, path, 0);
669
657
                if (mdfd < 0)
670
658
                        continue;
671
659
                if (ioctl(mdfd, GET_ARRAY_INFO, &array) == 0 ||