X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=Build.c;h=5c97d63072d04f10078e172857594eaf0aa2624b;hb=4dd2df0966ec2e43ea404df5de7adf9f0e1a8e40;hp=789aca45996bf8a37796e0de34f0e5192e3268a8;hpb=69207ff6ac9d905c096597de4f37ff9524265d9b;p=thirdparty%2Fmdadm.git diff --git a/Build.c b/Build.c index 789aca45..5c97d630 100644 --- a/Build.c +++ b/Build.c @@ -1,7 +1,7 @@ /* * mdadm - manage Linux "md" devices aka RAID arrays. * - * Copyright (C) 2001-2006 Neil Brown + * Copyright (C) 2001-2009 Neil Brown * * * This program is free software; you can redistribute it and/or modify @@ -19,12 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Neil Brown - * Email: - * Paper: Neil Brown - * School of Computer Science and Engineering - * The University of New South Wales - * Sydney, 2052 - * Australia + * Email: */ #include "mdadm.h" @@ -33,10 +28,8 @@ #define START_MD _IO (MD_MAJOR, 2) #define STOP_MD _IO (MD_MAJOR, 3) -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 Build(char *mddev, struct mddev_dev *devlist, + struct shape *s, struct context *c) { /* Build a linear or raid0 arrays without superblocks * We cannot really do any checks, we just do it. @@ -55,11 +48,13 @@ int Build(char *mddev, int chunk, int level, int layout, int vers; struct stat stb; int subdevs = 0, missing_disks = 0; - mddev_dev_t dv; + struct mddev_dev *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) { @@ -69,92 +64,99 @@ int Build(char *mddev, int chunk, int level, int layout, continue; } if (stat(dv->devname, &stb)) { - fprintf(stderr, Name ": Cannot find %s: %s\n", + pr_err("Cannot find %s: %s\n", dv->devname, strerror(errno)); return 1; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { - fprintf(stderr, Name ": %s is not a block device.\n", + pr_err("%s is not a block device.\n", dv->devname); return 1; } } - if (raiddisks != subdevs) { - fprintf(stderr, Name ": requested %d devices in array but listed %d\n", - raiddisks, subdevs); + if (s->raiddisks != subdevs) { + pr_err("requested %d devices in array but listed %d\n", + s->raiddisks, subdevs); return 1; } - if (layout == UnSet) - switch(level) { + if (s->layout == UnSet) + switch(s->level) { default: /* no layout */ - layout = 0; + s->layout = 0; break; case 10: - layout = 0x102; /* near=2, far=1 */ - if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to n1\n"); + s->layout = 0x102; /* near=2, far=1 */ + if (c->verbose > 0) + pr_err("layout defaults to n1\n"); break; case 5: case 6: - layout = map_name(r5layout, "default"); - if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(r5layout, layout)); + s->layout = map_name(r5layout, "default"); + if (c->verbose > 0) + pr_err("layout defaults to %s\n", map_num(r5layout, s->layout)); break; case LEVEL_FAULTY: - layout = map_name(faultylayout, "default"); + s->layout = map_name(faultylayout, "default"); - if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(faultylayout, layout)); + if (c->verbose > 0) + pr_err("layout defaults to %s\n", map_num(faultylayout, s->layout)); break; } /* We need to create the device. It can have no name. */ - mdfd = create_mddev(mddev, NULL, autof, LOCAL, NULL); - if (mdfd < 0) + map_lock(&map); + mdfd = create_mddev(mddev, NULL, c->autof, LOCAL, + chosen_name); + if (mdfd < 0) { + map_unlock(&map); return 1; + } + mddev = chosen_name; + + map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name); + map_unlock(&map); vers = md_get_version(mdfd); /* looks Ok, go for it */ if (vers >= 9000) { mdu_array_info_t array; - array.level = level; - array.size = 0; - array.nr_disks = raiddisks; - array.raid_disks = raiddisks; + array.level = s->level; + if (s->size == MAX_SIZE) + s->size = 0; + array.size = s->size; + array.nr_disks = s->raiddisks; + array.raid_disks = s->raiddisks; array.md_minor = 0; if (fstat(mdfd, &stb)==0) array.md_minor = minor(stb.st_rdev); array.not_persistent = 1; array.state = 0; /* not clean, but no errors */ - if (assume_clean) + if (s->assume_clean) array.state |= 1; - array.active_disks = raiddisks - missing_disks; - array.working_disks = raiddisks - missing_disks; + array.active_disks = s->raiddisks - missing_disks; + array.working_disks = s->raiddisks - missing_disks; array.spare_disks = 0; array.failed_disks = missing_disks; - if (chunk == 0 && (level==0 || level==LEVEL_LINEAR)) - chunk = 64; - array.chunk_size = chunk*1024; - array.layout = layout; + if (s->chunk == 0 && (s->level==0 || s->level==LEVEL_LINEAR)) + s->chunk = 64; + array.chunk_size = s->chunk*1024; + array.layout = s->layout; if (ioctl(mdfd, SET_ARRAY_INFO, &array)) { - fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n", + pr_err("SET_ARRAY_INFO failed for %s: %s\n", mddev, strerror(errno)); goto abort; } - } else if (bitmap_file) { - fprintf(stderr, Name ": bitmaps not supported with this kernel\n"); + } else if (s->bitmap_file) { + pr_err("bitmaps not supported with this kernel\n"); goto abort; } - if (bitmap_file && level <= 0) { - fprintf(stderr, Name ": bitmaps not meaningful with level %s\n", - map_num(pers, level)?:"given"); + if (s->bitmap_file && s->level <= 0) { + pr_err("bitmaps not meaningful with level %s\n", + map_num(pers, s->level)?:"given"); goto abort; } /* now add the devices */ @@ -164,26 +166,26 @@ int Build(char *mddev, int chunk, int level, int layout, if (strcmp("missing", dv->devname) == 0) continue; if (stat(dv->devname, &stb)) { - fprintf(stderr, Name ": Weird: %s has disappeared.\n", + pr_err("Weird: %s has disappeared.\n", dv->devname); goto abort; } if ((stb.st_mode & S_IFMT)!= S_IFBLK) { - fprintf(stderr, Name ": Wierd: %s is no longer a block device.\n", + pr_err("Weird: %s is no longer a block device.\n", dv->devname); goto abort; } fd = open(dv->devname, O_RDONLY|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", dv->devname, strerror(errno)); goto abort; } if (get_dev_size(fd, NULL, &dsize) && - (size == 0 || dsize < size)) - size = dsize; + (s->size == 0 || s->size == MAX_SIZE || dsize < s->size)) + s->size = dsize; close(fd); - if (vers>= 9000) { + if (vers >= 9000) { mdu_disk_info_t disk; disk.number = i; disk.raid_disk = i; @@ -193,13 +195,13 @@ int Build(char *mddev, int chunk, int level, int layout, disk.major = major(stb.st_rdev); disk.minor = minor(stb.st_rdev); if (ioctl(mdfd, ADD_NEW_DISK, &disk)) { - fprintf(stderr, Name ": ADD_NEW_DISK failed for %s: %s\n", + pr_err("ADD_NEW_DISK failed for %s: %s\n", dv->devname, strerror(errno)); goto abort; } } else { if (ioctl(mdfd, REGISTER_DEV, &stb.st_rdev)) { - fprintf(stderr, Name ": REGISTER_DEV failed for %s: %s.\n", + pr_err("REGISTER_DEV failed for %s: %s.\n", dv->devname, strerror(errno)); goto abort; } @@ -208,68 +210,74 @@ int Build(char *mddev, int chunk, int level, int layout, /* now to start it */ if (vers >= 9000) { mdu_param_t param; /* not used by syscall */ - if (bitmap_file) { - bitmap_fd = open(bitmap_file, O_RDWR); + if (s->bitmap_file) { + bitmap_fd = open(s->bitmap_file, O_RDWR); if (bitmap_fd < 0) { int major = BITMAP_MAJOR_HI; #if 0 - if (bitmap_chunk == UnSet) { - fprintf(stderr, Name ": %s cannot be openned.", - bitmap_file); + if (s->bitmap_chunk == UnSet) { + pr_err("%s cannot be openned.", + s->bitmap_file); goto abort; } #endif if (vers < 9003) { major = BITMAP_MAJOR_HOSTENDIAN; #ifdef __BIG_ENDIAN - fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n" + pr_err("Warning - bitmaps created on this kernel are not portable\n" " between different architectures. Consider upgrading the Linux kernel.\n"); #endif } - bitmapsize = size>>9; /* FIXME wrong for RAID10 */ - if (CreateBitmap(bitmap_file, 1, NULL, bitmap_chunk, - delay, write_behind, bitmapsize, major)) { + bitmapsize = s->size>>9; /* FIXME wrong for RAID10 */ + if (CreateBitmap(s->bitmap_file, 1, NULL, s->bitmap_chunk, + c->delay, s->write_behind, bitmapsize, major)) { goto abort; } - bitmap_fd = open(bitmap_file, O_RDWR); + bitmap_fd = open(s->bitmap_file, O_RDWR); if (bitmap_fd < 0) { - fprintf(stderr, Name ": %s cannot be openned.", - bitmap_file); + pr_err("%s cannot be openned.", + s->bitmap_file); goto abort; } } if (bitmap_fd >= 0) { if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) { - fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n", + pr_err("Cannot set bitmap file for %s: %s\n", mddev, strerror(errno)); goto abort; } } } if (ioctl(mdfd, RUN_ARRAY, ¶m)) { - fprintf(stderr, Name ": RUN_ARRAY failed: %s\n", + pr_err("RUN_ARRAY failed: %s\n", strerror(errno)); + if (s->chunk & (s->chunk-1)) { + cont_err("Problem may be that chunk size" + " is not a power of 2\n"); + } goto abort; } } else { unsigned long arg; arg=0; - while (chunk > 4096) { + while (s->chunk > 4096) { arg++; - chunk >>= 1; + s->chunk >>= 1; } - if (level == 0) - chunk |= 0x20000; - else chunk |= 0x10000; + if (s->level == 0) + arg |= 0x20000; + else + arg |= 0x10000; if (ioctl(mdfd, START_MD, arg)) { - fprintf(stderr, Name ": START_MD failed: %s\n", + pr_err("START_MD failed: %s\n", strerror(errno)); goto abort; } } - if (verbose >= 0) - fprintf(stderr, Name ": array %s built and started.\n", + if (c->verbose >= 0) + pr_err("array %s built and started.\n", mddev); + wait_for(mddev, mdfd); close(mdfd); return 0;