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

« back to all changes in this revision

Viewing changes to super0.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:
110
110
        } else
111
111
                printf("           UUID : %08x\n", sb->set_uuid0);
112
112
 
 
113
        if (sb->not_persistent)
 
114
                printf("           Eedk : not persistent\n");
 
115
 
113
116
        atime = sb->ctime;
114
117
        printf("  Creation Time : %.24s\n", ctime(&atime));
115
118
        c=map_num(pers, sb->level);
116
119
        printf("     Raid Level : %s\n", c?c:"-unknown-");
117
120
        if ((int)sb->level >= 0) {
118
121
                int ddsks=0;
119
 
                printf("    Device Size : %d%s\n", sb->size, human_size((long long)sb->size<<10));
 
122
                printf("  Used Dev Size : %d%s\n", sb->size,
 
123
                       human_size((long long)sb->size<<10));
120
124
                switch(sb->level) {
121
125
                case 1: ddsks=1;break;
122
126
                case 4:
276
280
        else
277
281
                printf("%08x", sb->set_uuid0);
278
282
}
 
283
 
 
284
static void export_super0(void *sbv)
 
285
{
 
286
        mdp_super_t *sb = sbv;
 
287
        printf("MD_UUID=");
 
288
        if (sb->minor_version >= 90)
 
289
                printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
 
290
                       sb->set_uuid2, sb->set_uuid3);
 
291
        else
 
292
                printf("%08x", sb->set_uuid0);
 
293
        printf("\n");
 
294
}
279
295
#endif
280
296
 
281
297
static int match_home0(void *sbv, char *homehost)
320
336
        info->array.ctime = sb->ctime;
321
337
        info->array.utime = sb->utime;
322
338
        info->array.chunk_size = sb->chunk_size;
 
339
        info->array.state = sb->state;
323
340
        info->component_size = sb->size*2;
324
341
 
325
342
        info->disk.state = sb->this_disk.state;
411
428
                        } else if (i >= sb->raid_disks && sb->disks[i].number == 0)
412
429
                                sb->disks[i].state = 0;
413
430
        }
414
 
        if (strcmp(update, "force")==0) {
 
431
        if (strcmp(update, "force-one")==0) {
 
432
                /* Not enough devices for a working array, so
 
433
                 * bring this one up-to-date.
 
434
                 */
415
435
                __u32 ehi = sb->events_hi, elo = sb->events_lo;
416
436
                sb->events_hi = (info->events>>32) & 0xFFFFFFFF;
417
437
                sb->events_lo = (info->events) & 0xFFFFFFFF;
418
438
                if (sb->events_hi != ehi ||
419
439
                    sb->events_lo != elo)
420
440
                        rv = 1;
 
441
        }
 
442
        if (strcmp(update, "force-array")==0) {
 
443
                /* degraded array and 'force' requested, so
 
444
                 * maybe need to mark it 'clean'
 
445
                 */
421
446
                if ((sb->level == 5 || sb->level == 4 || sb->level == 6) &&
422
447
                    (sb->state & (1 << MD_SB_CLEAN)) == 0) {
423
448
                        /* need to force clean */
434
459
                        rv = 1;
435
460
                }
436
461
        }
437
 
        if (strcmp(update, "newdev") == 0) {
438
 
                int d = info->disk.number;
439
 
                memset(&sb->disks[d], 0, sizeof(sb->disks[d]));
440
 
                sb->disks[d].number = d;
441
 
                sb->disks[d].major = info->disk.major;
442
 
                sb->disks[d].minor = info->disk.minor;
443
 
                sb->disks[d].raid_disk = info->disk.raid_disk;
444
 
                sb->disks[d].state = info->disk.state;
445
 
                sb->this_disk = sb->disks[d];
 
462
        if (strcmp(update, "linear-grow-new") == 0) {
 
463
                memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0]));
 
464
                sb->disks[info->disk.number].number = info->disk.number;
 
465
                sb->disks[info->disk.number].major = info->disk.major;
 
466
                sb->disks[info->disk.number].minor = info->disk.minor;
 
467
                sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
 
468
                sb->disks[info->disk.number].state = info->disk.state;
 
469
                sb->this_disk = sb->disks[info->disk.number];
446
470
        }
447
 
        if (strcmp(update, "grow") == 0) {
 
471
        if (strcmp(update, "linear-grow-update") == 0) {
448
472
                sb->raid_disks = info->array.raid_disks;
449
473
                sb->nr_disks = info->array.nr_disks;
450
474
                sb->active_disks = info->array.active_disks;
455
479
                sb->disks[info->disk.number].minor = info->disk.minor;
456
480
                sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
457
481
                sb->disks[info->disk.number].state = info->disk.state;
458
 
                if (sb->this_disk.number == info->disk.number)
459
 
                        sb->this_disk = sb->disks[info->disk.number];
460
482
        }
461
483
        if (strcmp(update, "resync") == 0) {
462
484
                /* make sure resync happens */
495
517
        return rv;
496
518
}
497
519
 
498
 
static __u64 event_super0(void *sbv)
499
 
{
500
 
        mdp_super_t *sb = sbv;
501
 
        return md_event(sb);
502
 
}
503
 
 
504
520
/*
505
521
 * For verion-0 superblock, the homehost is 'stored' in the
506
522
 * uuid.  8 bytes for a hash of the host leaving 8 bytes
511
527
 
512
528
 
513
529
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
514
 
                       unsigned long long size, char *ignored_name, char *homehost)
 
530
                       unsigned long long size, char *ignored_name, char *homehost,
 
531
                       int *uuid)
515
532
{
516
533
        mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
517
534
        int spares;
518
 
        int rfd;
519
535
        memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t));
520
536
 
521
537
        if (info->major_version == -1) {
531
547
                return 0;
532
548
        }
533
549
 
534
 
        rfd = open("/dev/urandom", O_RDONLY);
535
550
        sb->md_magic = MD_SB_MAGIC;
536
551
        sb->major_version = 0;
537
552
        sb->minor_version = 90;
538
553
        sb->patch_version = 0;
539
554
        sb->gvalid_words = 0; /* ignored */
540
 
        if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
541
 
                sb->set_uuid0 = random();
542
555
        sb->ctime = time(0);
543
556
        sb->level = info->level;
544
557
        if (size != info->size)
548
561
        sb->raid_disks = info->raid_disks;
549
562
        sb->md_minor = info->md_minor;
550
563
        sb->not_persistent = 0;
551
 
        if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
552
 
                sb->set_uuid1 = random();
553
 
                sb->set_uuid2 = random();
554
 
                sb->set_uuid3 = random();
 
564
        if (uuid) {
 
565
                sb->set_uuid0 = uuid[0];
 
566
                sb->set_uuid1 = uuid[1];
 
567
                sb->set_uuid2 = uuid[2];
 
568
                sb->set_uuid3 = uuid[3];
 
569
        } else {
 
570
                int rfd = open("/dev/urandom", O_RDONLY);
 
571
                if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
 
572
                        sb->set_uuid0 = random();
 
573
                if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
 
574
                        sb->set_uuid1 = random();
 
575
                        sb->set_uuid2 = random();
 
576
                        sb->set_uuid3 = random();
 
577
                }
 
578
                if (rfd >= 0)
 
579
                        close(rfd);
555
580
        }
556
 
        if (rfd >= 0)
557
 
                close(rfd);
558
581
        if (homehost) {
559
582
                char buf[20];
560
583
                char *hash = sha1_buffer(homehost,
594
617
 
595
618
static int store_super0(struct supertype *st, int fd, void *sbv)
596
619
{
597
 
        unsigned long size;
598
620
        unsigned long long dsize;
599
621
        unsigned long long offset;
600
622
        mdp_super_t *super = sbv;
601
 
    
602
 
#ifdef BLKGETSIZE64
603
 
        if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
604
 
#endif
605
 
        {
606
 
                if (ioctl(fd, BLKGETSIZE, &size))
607
 
                        return 1;
608
 
                else
609
 
                        dsize = ((unsigned long long)size)<<9;
610
 
        }
 
623
 
 
624
        if (!get_dev_size(fd, NULL, &dsize))
 
625
                return 1;
611
626
 
612
627
        if (dsize < MD_RESERVED_SECTORS*2*512)
613
628
                return 2;
707
722
         *  1 on cannot get superblock
708
723
         *  2 on superblock meaningless
709
724
         */
710
 
        unsigned long size;
711
725
        unsigned long long dsize;
712
726
        unsigned long long offset;
713
727
        mdp_super_t *super;
714
728
        int uuid[4];
715
729
        struct bitmap_super_s *bsb;
716
730
    
717
 
#ifdef BLKGETSIZE64
718
 
        if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
719
 
#endif
720
 
        {
721
 
                if (ioctl(fd, BLKGETSIZE, &size)) {
722
 
                        if (devname)
723
 
                                fprintf(stderr, Name ": cannot find device size for %s: %s\n",
724
 
                                        devname, strerror(errno));
725
 
                        return 1;
726
 
                } else
727
 
                        dsize = size << 9;
728
 
        }
 
731
        if (!get_dev_size(fd, devname, &dsize))
 
732
                return 1;
729
733
 
730
 
        if (dsize < MD_RESERVED_SECTORS*2) {
 
734
        if (dsize < MD_RESERVED_SECTORS*512 * 2) {
731
735
                if (devname)
732
 
                        fprintf(stderr, Name ": %s is too small for md: size is %ld sectors.\n",
733
 
                                devname, size);
 
736
                        fprintf(stderr, Name
 
737
                            ": %s is too small for md: size is %llu sectors.\n",
 
738
                                devname, dsize);
734
739
                return 1;
735
740
        }
736
741
 
835
840
        return MD_NEW_SIZE_SECTORS(devsize);
836
841
}
837
842
 
838
 
static int add_internal_bitmap0(struct supertype *st, void *sbv, int chunk, int delay, int write_behind, unsigned long long size, int may_change, int major)
 
843
static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
 
844
                                int delay, int write_behind,
 
845
                                unsigned long long size, int may_change,
 
846
                                int major)
839
847
{
840
848
        /*
841
849
         * The bitmap comes immediately after the superblock and must be 60K in size
846
854
        unsigned long long bits;
847
855
        unsigned long long max_bits = 60*1024*8;
848
856
        unsigned long long min_chunk;
 
857
        int chunk = *chunkp;
849
858
        mdp_super_t *sb = sbv;
850
859
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES);
851
860
 
871
880
        bms->daemon_sleep = __cpu_to_le32(delay);
872
881
        bms->sync_size = __cpu_to_le64(size);
873
882
        bms->write_behind = __cpu_to_le32(write_behind);
874
 
 
 
883
        *chunkp = chunk;
875
884
        return 1;
876
885
}
877
886
 
879
888
void locate_bitmap0(struct supertype *st, int fd, void *sbv)
880
889
{
881
890
        unsigned long long dsize;
882
 
        unsigned long size;
883
891
        unsigned long long offset;
884
 
#ifdef BLKGETSIZE64
885
 
        if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
886
 
#endif
887
 
        {
888
 
                if (ioctl(fd, BLKGETSIZE, &size))
889
 
                        return;
890
 
                else
891
 
                        dsize = ((unsigned long long)size)<<9;
892
 
        }
893
 
 
894
 
        if (dsize < MD_RESERVED_SECTORS*2)
 
892
 
 
893
        if (!get_dev_size(fd, NULL, &dsize))
 
894
                return;
 
895
 
 
896
        if (dsize < MD_RESERVED_SECTORS*512 * 2)
895
897
                return;
896
898
 
897
899
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
905
907
 
906
908
int write_bitmap0(struct supertype *st, int fd, void *sbv)
907
909
{
908
 
        unsigned long size;
909
910
        unsigned long long dsize;
910
911
        unsigned long long offset;
911
912
        mdp_super_t *sb = sbv;
915
916
        int towrite, n;
916
917
        char buf[4096];
917
918
 
918
 
#ifdef BLKGETSIZE64
919
 
        if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
920
 
#endif
921
 
        {
922
 
                if (ioctl(fd, BLKGETSIZE, &size))
923
 
                        return 1;
924
 
                else
925
 
                        dsize = ((unsigned long long)size)<<9;
926
 
        }
927
 
 
928
 
        if (dsize < MD_RESERVED_SECTORS*2)
 
919
        if (!get_dev_size(fd, NULL, &dsize))
 
920
                return 1;
 
921
 
 
922
 
 
923
        if (dsize < MD_RESERVED_SECTORS*512 * 2)
929
924
        return -1;
930
925
 
931
926
        offset = MD_NEW_SIZE_SECTORS(dsize>>9);
964
959
        .brief_examine_super = brief_examine_super0,
965
960
        .detail_super = detail_super0,
966
961
        .brief_detail_super = brief_detail_super0,
 
962
        .export_super = export_super0,
967
963
#endif
968
964
        .match_home = match_home0,
969
965
        .uuid_from_super = uuid_from_super0,
970
966
        .getinfo_super = getinfo_super0,
971
967
        .update_super = update_super0,
972
 
        .event_super = event_super0,
973
968
        .init_super = init_super0,
974
969
        .add_to_super = add_to_super0,
975
970
        .store_super = store_super0,