Support RAID on virtio devices, and others.

* grub-core/kern/emu/getroot.c [__MINGW32__] (find_root_device):
Rename to ...
[__MINGW32__] (grub_find_device): ... this.
[! __MINGW32__ && ! __CYGWIN__] (find_root_device): Rename to ...
[! __MINGW32__ && ! __CYGWIN__] (grub_find_device): ... this.  Use a
reasonable default if dir is NULL.
[! __MINGW32__ && __CYGWIN__] (find_cygwin_root_device): Rename to
...
[! __MINGW32__ && __CYGWIN__] (grub_find_device): ... this.
(grub_guess_root_device): Update callers.
* include/grub/emu/getroot.h (grub_find_device): Add prototype.
* util/raid.c (grub_util_getdiskname): Remove.
(grub_util_raid_getmembers): Use grub_find_device rather than
grub_util_getdiskname.
This commit is contained in:
Colin Watson 2010-09-16 14:55:28 +01:00
parent e5bfc130a4
commit 108538d8ff
4 changed files with 46 additions and 34 deletions

View file

@ -1,3 +1,23 @@
2010-09-16 Colin Watson <cjwatson@ubuntu.com>
Support RAID on virtio devices, and others.
* grub-core/kern/emu/getroot.c [__MINGW32__] (find_root_device):
Rename to ...
[__MINGW32__] (grub_find_device): ... this.
[! __MINGW32__ && ! __CYGWIN__] (find_root_device): Rename to ...
[! __MINGW32__ && ! __CYGWIN__] (grub_find_device): ... this. Use a
reasonable default if dir is NULL.
[! __MINGW32__ && __CYGWIN__] (find_cygwin_root_device): Rename to
...
[! __MINGW32__ && __CYGWIN__] (grub_find_device): ... this.
(grub_guess_root_device): Update callers.
* include/grub/emu/getroot.h (grub_find_device): Add prototype.
* util/raid.c (grub_util_getdiskname): Remove.
(grub_util_raid_getmembers): Use grub_find_device rather than
grub_util_getdiskname.
2010-09-16 Colin Watson <cjwatson@ubuntu.com> 2010-09-16 Colin Watson <cjwatson@ubuntu.com>
* docs/grub.texi (serial): Remove obsolete comment about GRUB * docs/grub.texi (serial): Remove obsolete comment about GRUB

View file

@ -228,8 +228,8 @@ find_root_device_from_libzfs (const char *dir)
#ifdef __MINGW32__ #ifdef __MINGW32__
static char * char *
find_root_device (const char *dir __attribute__ ((unused)), grub_find_device (const char *dir __attribute__ ((unused)),
dev_t dev __attribute__ ((unused))) dev_t dev __attribute__ ((unused)))
{ {
return 0; return 0;
@ -237,13 +237,22 @@ find_root_device (const char *dir __attribute__ ((unused)),
#elif ! defined(__CYGWIN__) #elif ! defined(__CYGWIN__)
static char * char *
find_root_device (const char *dir, dev_t dev) grub_find_device (const char *dir, dev_t dev)
{ {
DIR *dp; DIR *dp;
char *saved_cwd; char *saved_cwd;
struct dirent *ent; struct dirent *ent;
if (! dir)
{
#ifdef __CYGWIN__
return NULL;
#else
dir = "/dev";
#endif
}
dp = opendir (dir); dp = opendir (dir);
if (! dp) if (! dp)
return 0; return 0;
@ -292,7 +301,7 @@ find_root_device (const char *dir, dev_t dev)
/* Find it recursively. */ /* Find it recursively. */
char *res; char *res;
res = find_root_device (ent->d_name, dev); res = grub_find_device (ent->d_name, dev);
if (res) if (res)
{ {
@ -402,8 +411,8 @@ get_bootsec_serial (const char *os_dev, int mbr)
return serial; return serial;
} }
static char * char *
find_cygwin_root_device (const char *path, dev_t dev) grub_find_device (const char *path, dev_t dev)
{ {
/* No root device for /cygdrive. */ /* No root device for /cygdrive. */
if (dev == (DEV_CYGDRIVE_MAJOR << 16)) if (dev == (DEV_CYGDRIVE_MAJOR << 16))
@ -424,7 +433,7 @@ find_cygwin_root_device (const char *path, dev_t dev)
/* Cygwin returns the partition serial number in stat.st_dev. /* Cygwin returns the partition serial number in stat.st_dev.
This is never identical to the device number of the emulated This is never identical to the device number of the emulated
/dev/sdXN device, so above find_root_device () does not work. /dev/sdXN device, so above grub_find_device () does not work.
Search the partition with the same serial in boot sector instead. */ Search the partition with the same serial in boot sector instead. */
char devpath[sizeof ("/dev/sda15") + 13]; /* Size + Paranoia. */ char devpath[sizeof ("/dev/sda15") + 13]; /* Size + Paranoia. */
int d; int d;
@ -529,12 +538,12 @@ grub_guess_root_device (const char *dir)
#ifdef __CYGWIN__ #ifdef __CYGWIN__
/* Cygwin specific function. */ /* Cygwin specific function. */
os_dev = find_cygwin_root_device (dir, st.st_dev); os_dev = grub_find_device (dir, st.st_dev);
#else #else
/* This might be truly slow, but is there any better way? */ /* This might be truly slow, but is there any better way? */
os_dev = find_root_device ("/dev", st.st_dev); os_dev = grub_find_device ("/dev", st.st_dev);
#endif #endif
#endif /* !__GNU__ */ #endif /* !__GNU__ */

View file

@ -19,12 +19,15 @@
#ifndef GRUB_UTIL_GETROOT_HEADER #ifndef GRUB_UTIL_GETROOT_HEADER
#define GRUB_UTIL_GETROOT_HEADER 1 #define GRUB_UTIL_GETROOT_HEADER 1
#include <sys/types.h>
enum grub_dev_abstraction_types { enum grub_dev_abstraction_types {
GRUB_DEV_ABSTRACTION_NONE, GRUB_DEV_ABSTRACTION_NONE,
GRUB_DEV_ABSTRACTION_LVM, GRUB_DEV_ABSTRACTION_LVM,
GRUB_DEV_ABSTRACTION_RAID, GRUB_DEV_ABSTRACTION_RAID,
}; };
char *grub_find_device (const char *dir, dev_t dev);
char *grub_guess_root_device (const char *dir); char *grub_guess_root_device (const char *dir);
int grub_util_get_dev_abstraction (const char *os_dev); int grub_util_get_dev_abstraction (const char *os_dev);
char *grub_util_get_grub_dev (const char *os_dev); char *grub_util_get_grub_dev (const char *os_dev);

View file

@ -22,40 +22,19 @@
#include <grub/emu/misc.h> #include <grub/emu/misc.h>
#include <grub/util/misc.h> #include <grub/util/misc.h>
#include <grub/util/raid.h> #include <grub/util/raid.h>
#include <grub/emu/getroot.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/major.h> #include <linux/major.h>
#include <linux/raid/md_p.h> #include <linux/raid/md_p.h>
#include <linux/raid/md_u.h> #include <linux/raid/md_u.h>
static char *
grub_util_getdiskname (int major, int minor)
{
char *name = xmalloc (15);
if (major == LOOP_MAJOR)
sprintf (name, "/dev/loop%d", minor);
else if (major == IDE0_MAJOR)
sprintf (name, "/dev/hd%c", 'a' + minor / 64);
else if (major == IDE1_MAJOR)
sprintf (name, "/dev/hd%c", 'c' + minor / 64);
else if (major == IDE2_MAJOR)
sprintf (name, "/dev/hd%c", 'e' + minor / 64);
else if (major == IDE3_MAJOR)
sprintf (name, "/dev/hd%c", 'g' + minor / 64);
else if (major == SCSI_DISK0_MAJOR)
sprintf (name, "/dev/sd%c", 'a' + minor / 16);
else
grub_util_error ("unknown device number: %d, %d", major, minor);
return name;
}
char ** char **
grub_util_raid_getmembers (char *name) grub_util_raid_getmembers (char *name)
{ {
@ -100,7 +79,8 @@ grub_util_raid_getmembers (char *name)
if (disk.state & (1 << MD_DISK_ACTIVE)) if (disk.state & (1 << MD_DISK_ACTIVE))
{ {
devicelist[j] = grub_util_getdiskname (disk.major, disk.minor); devicelist[j] = grub_find_device (NULL,
makedev (disk.major, disk.minor));
j++; j++;
} }
} }