linux/init/do_mounts_md.c
<<
>>
Prefs
   1
   2#include <linux/raid/md.h>
   3
   4#include "do_mounts.h"
   5
   6/*
   7 * When md (and any require personalities) are compiled into the kernel
   8 * (not a module), arrays can be assembles are boot time using with AUTODETECT
   9 * where specially marked partitions are registered with md_autodetect_dev(),
  10 * and with MD_BOOT where devices to be collected are given on the boot line
  11 * with md=.....
  12 * The code for that is here.
  13 */
  14
  15static int __initdata raid_noautodetect, raid_autopart;
  16
  17static struct {
  18        int minor;
  19        int partitioned;
  20        int level;
  21        int chunk;
  22        char *device_names;
  23} md_setup_args[256] __initdata;
  24
  25static int md_setup_ents __initdata;
  26
  27extern int mdp_major;
  28/*
  29 * Parse the command-line parameters given our kernel, but do not
  30 * actually try to invoke the MD device now; that is handled by
  31 * md_setup_drive after the low-level disk drivers have initialised.
  32 *
  33 * 27/11/1999: Fixed to work correctly with the 2.3 kernel (which
  34 *             assigns the task of parsing integer arguments to the
  35 *             invoked program now).  Added ability to initialise all
  36 *             the MD devices (by specifying multiple "md=" lines)
  37 *             instead of just one.  -- KTK
  38 * 18May2000: Added support for persistent-superblock arrays:
  39 *             md=n,0,factor,fault,device-list   uses RAID0 for device n
  40 *             md=n,-1,factor,fault,device-list  uses LINEAR for device n
  41 *             md=n,device-list      reads a RAID superblock from the devices
  42 *             elements in device-list are read by name_to_kdev_t so can be
  43 *             a hex number or something like /dev/hda1 /dev/sdb
  44 * 2001-06-03: Dave Cinege <dcinege@psychosis.com>
  45 *              Shifted name_to_kdev_t() and related operations to md_set_drive()
  46 *              for later execution. Rewrote section to make devfs compatible.
  47 */
  48static int __init md_setup(char *str)
  49{
  50        int minor, level, factor, fault, partitioned = 0;
  51        char *pername = "";
  52        char *str1;
  53        int ent;
  54
  55        if (*str == 'd') {
  56                partitioned = 1;
  57                str++;
  58        }
  59        if (get_option(&str, &minor) != 2) {    /* MD Number */
  60                printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
  61                return 0;
  62        }
  63        str1 = str;
  64        for (ent=0 ; ent< md_setup_ents ; ent++)
  65                if (md_setup_args[ent].minor == minor &&
  66                    md_setup_args[ent].partitioned == partitioned) {
  67                        printk(KERN_WARNING "md: md=%s%d, Specified more than once. "
  68                               "Replacing previous definition.\n", partitioned?"d":"", minor);
  69                        break;
  70                }
  71        if (ent >= ARRAY_SIZE(md_setup_args)) {
  72                printk(KERN_WARNING "md: md=%s%d - too many md initialisations\n", partitioned?"d":"", minor);
  73                return 0;
  74        }
  75        if (ent >= md_setup_ents)
  76                md_setup_ents++;
  77        switch (get_option(&str, &level)) {     /* RAID level */
  78        case 2: /* could be 0 or -1.. */
  79                if (level == 0 || level == LEVEL_LINEAR) {
  80                        if (get_option(&str, &factor) != 2 ||   /* Chunk Size */
  81                                        get_option(&str, &fault) != 2) {
  82                                printk(KERN_WARNING "md: Too few arguments supplied to md=.\n");
  83                                return 0;
  84                        }
  85                        md_setup_args[ent].level = level;
  86                        md_setup_args[ent].chunk = 1 << (factor+12);
  87                        if (level ==  LEVEL_LINEAR)
  88                                pername = "linear";
  89                        else
  90                                pername = "raid0";
  91                        break;
  92                }
  93                /* FALL THROUGH */
  94        case 1: /* the first device is numeric */
  95                str = str1;
  96                /* FALL THROUGH */
  97        case 0:
  98                md_setup_args[ent].level = LEVEL_NONE;
  99                pername="super-block";
 100        }
 101
 102        printk(KERN_INFO "md: Will configure md%d (%s) from %s, below.\n",
 103                minor, pername, str);
 104        md_setup_args[ent].device_names = str;
 105        md_setup_args[ent].partitioned = partitioned;
 106        md_setup_args[ent].minor = minor;
 107
 108        return 1;
 109}
 110
 111#define MdpMinorShift 6
 112
 113static void __init md_setup_drive(void)
 114{
 115        int minor, i, ent, partitioned;
 116        dev_t dev;
 117        dev_t devices[MD_SB_DISKS+1];
 118
 119        for (ent = 0; ent < md_setup_ents ; ent++) {
 120                int fd;
 121                int err = 0;
 122                char *devname;
 123                mdu_disk_info_t dinfo;
 124                char name[16];
 125
 126                minor = md_setup_args[ent].minor;
 127                partitioned = md_setup_args[ent].partitioned;
 128                devname = md_setup_args[ent].device_names;
 129
 130                sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor);
 131                if (partitioned)
 132                        dev = MKDEV(mdp_major, minor << MdpMinorShift);
 133                else
 134                        dev = MKDEV(MD_MAJOR, minor);
 135                create_dev(name, dev);
 136                for (i = 0; i < MD_SB_DISKS && devname != 0; i++) {
 137                        char *p;
 138                        char comp_name[64];
 139                        u32 rdev;
 140
 141                        p = strchr(devname, ',');
 142                        if (p)
 143                                *p++ = 0;
 144
 145                        dev = name_to_dev_t(devname);
 146                        if (strncmp(devname, "/dev/", 5) == 0)
 147                                devname += 5;
 148                        snprintf(comp_name, 63, "/dev/%s", devname);
 149                        rdev = bstat(comp_name);
 150                        if (rdev)
 151                                dev = new_decode_dev(rdev);
 152                        if (!dev) {
 153                                printk(KERN_WARNING "md: Unknown device name: %s\n", devname);
 154                                break;
 155                        }
 156
 157                        devices[i] = dev;
 158
 159                        devname = p;
 160                }
 161                devices[i] = 0;
 162
 163                if (!i)
 164                        continue;
 165
 166                printk(KERN_INFO "md: Loading md%s%d: %s\n",
 167                        partitioned ? "_d" : "", minor,
 168                        md_setup_args[ent].device_names);
 169
 170                fd = sys_open(name, 0, 0);
 171                if (fd < 0) {
 172                        printk(KERN_ERR "md: open failed - cannot start "
 173                                        "array %s\n", name);
 174                        continue;
 175                }
 176                if (sys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) {
 177                        printk(KERN_WARNING
 178                               "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
 179                               minor);
 180                        sys_close(fd);
 181                        continue;
 182                }
 183
 184                if (md_setup_args[ent].level != LEVEL_NONE) {
 185                        /* non-persistent */
 186                        mdu_array_info_t ainfo;
 187                        ainfo.level = md_setup_args[ent].level;
 188                        ainfo.size = 0;
 189                        ainfo.nr_disks =0;
 190                        ainfo.raid_disks =0;
 191                        while (devices[ainfo.raid_disks])
 192                                ainfo.raid_disks++;
 193                        ainfo.md_minor =minor;
 194                        ainfo.not_persistent = 1;
 195
 196                        ainfo.state = (1 << MD_SB_CLEAN);
 197                        ainfo.layout = 0;
 198                        ainfo.chunk_size = md_setup_args[ent].chunk;
 199                        err = sys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo);
 200                        for (i = 0; !err && i <= MD_SB_DISKS; i++) {
 201                                dev = devices[i];
 202                                if (!dev)
 203                                        break;
 204                                dinfo.number = i;
 205                                dinfo.raid_disk = i;
 206                                dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC);
 207                                dinfo.major = MAJOR(dev);
 208                                dinfo.minor = MINOR(dev);
 209                                err = sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
 210                        }
 211                } else {
 212                        /* persistent */
 213                        for (i = 0; i <= MD_SB_DISKS; i++) {
 214                                dev = devices[i];
 215                                if (!dev)
 216                                        break;
 217                                dinfo.major = MAJOR(dev);
 218                                dinfo.minor = MINOR(dev);
 219                                sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo);
 220                        }
 221                }
 222                if (!err)
 223                        err = sys_ioctl(fd, RUN_ARRAY, 0);
 224                if (err)
 225                        printk(KERN_WARNING "md: starting md%d failed\n", minor);
 226                else {
 227                        /* reread the partition table.
 228                         * I (neilb) and not sure why this is needed, but I cannot
 229                         * boot a kernel with devfs compiled in from partitioned md
 230                         * array without it
 231                         */
 232                        sys_close(fd);
 233                        fd = sys_open(name, 0, 0);
 234                        sys_ioctl(fd, BLKRRPART, 0);
 235                }
 236                sys_close(fd);
 237        }
 238}
 239
 240static int __init raid_setup(char *str)
 241{
 242        int len, pos;
 243
 244        len = strlen(str) + 1;
 245        pos = 0;
 246
 247        while (pos < len) {
 248                char *comma = strchr(str+pos, ',');
 249                int wlen;
 250                if (comma)
 251                        wlen = (comma-str)-pos;
 252                else    wlen = (len-1)-pos;
 253
 254                if (!strncmp(str, "noautodetect", wlen))
 255                        raid_noautodetect = 1;
 256                if (strncmp(str, "partitionable", wlen)==0)
 257                        raid_autopart = 1;
 258                if (strncmp(str, "part", wlen)==0)
 259                        raid_autopart = 1;
 260                pos += wlen+1;
 261        }
 262        return 1;
 263}
 264
 265__setup("raid=", raid_setup);
 266__setup("md=", md_setup);
 267
 268void __init md_run_setup(void)
 269{
 270        create_dev("/dev/md0", MKDEV(MD_MAJOR, 0));
 271        if (raid_noautodetect)
 272                printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
 273        else {
 274                int fd = sys_open("/dev/md0", 0, 0);
 275                if (fd >= 0) {
 276                        sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
 277                        sys_close(fd);
 278                }
 279        }
 280        md_setup_drive();
 281}
 282