automatic raid members addition

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-04-22 13:55:30 +02:00
parent 65b4742cd7
commit 4defebbec8
8 changed files with 30 additions and 45 deletions

View file

@ -165,6 +165,7 @@ kernel = {
emu = kern/emu/cache.S;
emu = kern/emu/console.c;
emu = kern/emu/getroot.c;
emu = kern/emu/raid.c;
emu = kern/emu/hostdisk.c;
emu = kern/emu/hostfs.c;
emu = kern/emu/main.c;

View file

@ -198,16 +198,6 @@ grub_lvm_open (const char *name, grub_disk_t disk,
if (! lv && !scan_depth &&
pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED))
{
#ifdef GRUB_UTIL
if (explicit)
{
char buf[grub_strlen (name) + sizeof ("/dev/mapper/")];
grub_memcpy (buf, "/dev/mapper/", sizeof ("/dev/mapper/"));
grub_strcpy (buf + sizeof ("/dev/mapper/") - 1,
name + sizeof ("lvm/") - 1);
grub_util_pull_device (buf);
}
#endif
scan_for = name;
scan_depth++;
grub_device_iterate (&grub_lvm_scan_device);

View file

@ -854,9 +854,20 @@ grub_util_pull_device (const char *os_dev)
grub_util_pull_device (subdev);
}
dm_tree_free (tree);
return;
}
#endif
return;
case GRUB_DEV_ABSTRACTION_RAID:
#ifdef __linux__
{
char **devicelist = grub_util_raid_getmembers (os_dev, 0);
int i;
for (i = 0; devicelist[i];i++)
grub_util_pull_device (devicelist[i]);
free (devicelist);
}
#endif
return;
default: /* GRUB_DEV_ABSTRACTION_NONE */
grub_util_biosdisk_get_grub_dev (os_dev);
@ -869,6 +880,8 @@ grub_util_get_grub_dev (const char *os_dev)
{
char *grub_dev = NULL;
grub_util_pull_device (os_dev);
switch (grub_util_get_dev_abstraction (os_dev))
{
case GRUB_DEV_ABSTRACTION_LVM:

92
grub-core/kern/emu/raid.c Normal file
View file

@ -0,0 +1,92 @@
/* raid.c - RAID support for GRUB utils. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
/* We only support RAID on Linux. */
#ifdef __linux__
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/emu/getroot.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/types.h>
#include <linux/major.h>
#include <linux/raid/md_p.h>
#include <linux/raid/md_u.h>
char **
grub_util_raid_getmembers (const char *name, int bootable)
{
int fd, ret, i, j;
char **devicelist;
mdu_version_t version;
mdu_array_info_t info;
mdu_disk_info_t disk;
fd = open (name, O_RDONLY);
if (fd == -1)
grub_util_error ("can't open %s: %s", name, strerror (errno));
ret = ioctl (fd, RAID_VERSION, &version);
if (ret != 0)
grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno));
if ((version.major != 0 || version.minor != 90)
&& (version.major != 1 || version.minor != 0)
&& (version.major != 1 || version.minor != 1)
&& (version.major != 1 || version.minor != 2))
grub_util_error ("unsupported RAID version: %d.%d",
version.major, version.minor);
if (bootable && (version.major != 0 || version.minor != 90))
grub_util_error ("unsupported RAID version: %d.%d",
version.major, version.minor);
ret = ioctl (fd, GET_ARRAY_INFO, &info);
if (ret != 0)
grub_util_error ("ioctl GET_ARRAY_INFO error: %s", strerror (errno));
devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *));
for (i = 0, j = 0; i <info.nr_disks; i++)
{
disk.number = i;
ret = ioctl (fd, GET_DISK_INFO, &disk);
if (ret != 0)
grub_util_error ("ioctl GET_DISK_INFO error: %s", strerror (errno));
if (disk.state & (1 << MD_DISK_ACTIVE))
{
devicelist[j] = grub_find_device (NULL,
makedev (disk.major, disk.minor));
j++;
}
}
devicelist[j] = NULL;
return devicelist;
}
#endif /* ! __linux__ */