diff --git a/ChangeLog b/ChangeLog index e6aace254..2eaf669c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,51 @@ +2011-07-07 Vladimir Serbinenko + + Lazy device scanning. + + * Makefile.util.def (libgrubkern.a): Add grub-core/kern/emu/raid.c. + (grub-setup): Remove util/raid.c. + * grub-core/Makefile.core.def (kernel): Add kern/emu/raid.c on emu. + * grub-core/disk/lvm.c (scan_depth): New variable. + (grub_lvm_iterate): Rescan if necessary. + (find_lv): New function based on grub_lvm_open. + (grub_lvm_open): Use find_lv. Rescan on error. + (is_node_readable): New function. + (is_lv_readable): Likewise. + (grub_lvm_scan_device): Skip already found disks. + (do_lvm_scan): New function. Move grub_lvm_scan_device inside of it. + Stop if searched device is found and readable. + * grub-core/disk/raid.c (inscnt): New variable. + (scan_depth): Likewise. + (scan_devices): New function based on grub_raid_register. Abort if + looked for device is found. + (grub_raid_iterate): Rescan if needed. + (find_array): NEw function based on -grub_raid_open. + (grub_raid_open): Use find_array and rescan. + (insert_array): Set became_readable_at. + * grub-core/kern/disk.c (grub_disk_dev_iterate): Iterate though "pull. + * grub-core/kern/emu/getroot.c (grub_util_open_dm) [HAVE_DEVICE_MAPPER]: + New function. + (grub_util_is_lvm) [HAVE_DEVICE_MAPPER]: Use grub_util_open_dm. + (grub_util_pull_device): New function. + (grub_util_get_grub_dev): Call grub_util_pull_device. + * util/raid.c: Moved to .. + * grub-core/kern/emu/raid.c: ... here. + (grub_util_raid_getmembers): New parameter "bootable". + All users updated. Support 1.x. + * include/grub/ata.h (grub_ata_dev): Change iterate prototype. + All users updated. + * include/grub/disk.h (grub_disk_pull_t): New enum. + (grub_disk_dev): Change iterate prototype. + All users updated. + * include/grub/emu/getroot.h (grub_util_raid_getmembers) [__linux__]: + New proto. + * include/grub/emu/hostdisk.h (grub_util_pull_device): Likewise. + * include/grub/lvm.h (grub_lvm_lv): New members fullname and compatname. + * include/grub/raid.h (grub_raid_array): New member became_readable_at. + * include/grub/scsi.h (grub_scsi_dev): Change iterate prototype. + All users updated. + * include/grub/util/raid.h: Removed. + 2011-07-06 Vladimir Serbinenko * po/POTFILES.in: Regenerate. diff --git a/Makefile.util.def b/Makefile.util.def index 1fcd9465e..9722a8505 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -10,6 +10,7 @@ library = { common = grub-core/kern/device.c; common = grub-core/kern/disk.c; common = grub-core/kern/emu/getroot.c; + common = grub-core/kern/emu/raid.c; common = grub-core/kern/emu/hostdisk.c; common = grub-core/kern/emu/misc.c; common = grub-core/kern/emu/mm.c; @@ -271,7 +272,6 @@ program = { installdir = sbin; mansection = 8; common = util/grub-setup.c; - common = util/raid.c; common = util/lvm.c; common = grub-core/lib/reed_solomon.c; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 7bceaa98f..73d462185 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -196,6 +196,7 @@ kernel = { emu = kern/emu/cache_s.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; diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 415004fcf..38c4d5e2d 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -453,10 +453,14 @@ grub_ahci_restore_hw (void) static int -grub_ahci_iterate (int (*hook) (int id, int bus)) +grub_ahci_iterate (int (*hook) (int id, int bus), + grub_disk_pull_t pull) { struct grub_ahci_device *dev; + if (pull != GRUB_DISK_PULL_NONE) + return 0; + FOR_LIST_ELEMENTS(dev, grub_ahci_devices) if (hook (GRUB_SCSI_SUBSYSTEM_AHCI, dev->num)) return 1; diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index 7dff30931..170bf521d 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -79,7 +79,8 @@ arcdisk_hash_add (char *devpath) static int -grub_arcdisk_iterate (int (*hook_in) (const char *name)) +grub_arcdisk_iterate (int (*hook_in) (const char *name), + grub_disk_pull_t pull) { auto int hook (const char *name, const struct grub_arc_component *comp); int hook (const char *name, const struct grub_arc_component *comp) @@ -90,6 +91,9 @@ grub_arcdisk_iterate (int (*hook_in) (const char *name)) return 0; return hook_in (name); } + if (pull != GRUB_DISK_PULL_NONE) + return 0; + return grub_arc_iterate_devs (hook, 1); } diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index a8ccc2c59..8add7f4de 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -374,7 +374,8 @@ grub_ata_real_open (int id, int bus) } static int -grub_ata_iterate (int (*hook_in) (const char *name)) +grub_ata_iterate (int (*hook_in) (const char *name), + grub_disk_pull_t pull) { auto int hook (int id, int bus); int hook (int id, int bus) @@ -405,7 +406,7 @@ grub_ata_iterate (int (*hook_in) (const char *name)) grub_ata_dev_t p; for (p = grub_ata_dev_list; p; p = p->next) - if (p->iterate && p->iterate (hook)) + if (p->iterate && p->iterate (hook, pull)) return 1; return 0; } @@ -541,7 +542,8 @@ grub_atapi_open (int id, int bus, struct grub_scsi *scsi) } static int -grub_atapi_iterate (int NESTED_FUNC_ATTR (*hook_in) (int id, int bus, int luns)) +grub_atapi_iterate (int NESTED_FUNC_ATTR (*hook_in) (int id, int bus, int luns), + grub_disk_pull_t pull) { auto int hook (int id, int bus); int hook (int id, int bus) @@ -569,7 +571,7 @@ grub_atapi_iterate (int NESTED_FUNC_ATTR (*hook_in) (int id, int bus, int luns)) grub_ata_dev_t p; for (p = grub_ata_dev_list; p; p = p->next) - if (p->iterate && p->iterate (hook)) + if (p->iterate && p->iterate (hook, pull)) return 1; return 0; } diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 07f0f6859..85969cc1d 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -378,34 +378,43 @@ enumerate_disks (void) } static int -grub_efidisk_iterate (int (*hook) (const char *name)) +grub_efidisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_efidisk_data *d; char buf[16]; int count; - for (d = fd_devices, count = 0; d; d = d->next, count++) + switch (pull) { - grub_snprintf (buf, sizeof (buf), "fd%d", count); - grub_dprintf ("efidisk", "iterating %s\n", buf); - if (hook (buf)) - return 1; - } + case GRUB_DISK_PULL_NONE: + for (d = hd_devices, count = 0; d; d = d->next, count++) + { + grub_snprintf (buf, sizeof (buf), "hd%d", count); + grub_dprintf ("efidisk", "iterating %s\n", buf); + if (hook (buf)) + return 1; + } + break; + case GRUB_DISK_PULL_REMOVABLE: + for (d = fd_devices, count = 0; d; d = d->next, count++) + { + grub_snprintf (buf, sizeof (buf), "fd%d", count); + grub_dprintf ("efidisk", "iterating %s\n", buf); + if (hook (buf)) + return 1; + } - for (d = hd_devices, count = 0; d; d = d->next, count++) - { - grub_snprintf (buf, sizeof (buf), "hd%d", count); - grub_dprintf ("efidisk", "iterating %s\n", buf); - if (hook (buf)) - return 1; - } - - for (d = cd_devices, count = 0; d; d = d->next, count++) - { - grub_snprintf (buf, sizeof (buf), "cd%d", count); - grub_dprintf ("efidisk", "iterating %s\n", buf); - if (hook (buf)) - return 1; + for (d = cd_devices, count = 0; d; d = d->next, count++) + { + grub_snprintf (buf, sizeof (buf), "cd%d", count); + grub_dprintf ("efidisk", "iterating %s\n", buf); + if (hook (buf)) + return 1; + } + break; + default: + return 0; } return 0; @@ -734,7 +743,9 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) sdp = dup_dp; - grub_efidisk_iterate (find_parent_disk); + grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_NONE); + if (!parent) + grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_REMOVABLE); grub_free (dup_dp); if (! parent) @@ -774,7 +785,9 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) sdp = dp; - grub_efidisk_iterate (find_parent_disk); + grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_NONE); + if (!parent) + grub_efidisk_iterate (find_parent_disk, GRUB_DISK_PULL_REMOVABLE); if (!parent) return NULL; device_name = grub_strdup (parent->name); diff --git a/grub-core/disk/host.c b/grub-core/disk/host.c index c51966293..5ee0d2e56 100644 --- a/grub-core/disk/host.c +++ b/grub-core/disk/host.c @@ -27,8 +27,12 @@ int grub_disk_host_i_want_a_reference; static int -grub_host_iterate (int (*hook) (const char *name)) +grub_host_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { + if (pull != GRUB_DISK_PULL_NONE) + return 0; + if (hook ("host")) return 1; return 0; diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index f28aa8b8e..e152b9d89 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -284,37 +284,46 @@ grub_biosdisk_call_hook (int (*hook) (const char *name), int drive) } static int -grub_biosdisk_iterate (int (*hook) (const char *name)) +grub_biosdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull __attribute__ ((unused))) { - int drive; int num_floppies; + int drive; /* For hard disks, attempt to read the MBR. */ - for (drive = 0x80; drive < 0x90; drive++) + switch (pull) { - if (grub_biosdisk_rw_standard (0x02, drive, 0, 0, 1, 1, - GRUB_MEMORY_MACHINE_SCRATCH_SEG) != 0) + case GRUB_DISK_PULL_NONE: + for (drive = 0x80; drive < 0x90; drive++) { - grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive); - break; + if (grub_biosdisk_rw_standard (0x02, drive, 0, 0, 1, 1, + GRUB_MEMORY_MACHINE_SCRATCH_SEG) != 0) + { + grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive); + break; + } + + if (grub_biosdisk_call_hook (hook, drive)) + return 1; + } + return 0; + + case GRUB_DISK_PULL_REMOVABLE: + if (cd_drive) + { + if (grub_biosdisk_call_hook (hook, cd_drive)) + return 1; } - if (grub_biosdisk_call_hook (hook, drive)) - return 1; + /* For floppy disks, we can get the number safely. */ + num_floppies = grub_biosdisk_get_num_floppies (); + for (drive = 0; drive < num_floppies; drive++) + if (grub_biosdisk_call_hook (hook, drive)) + return 1; + return 0; + default: + return 0; } - - if (cd_drive) - { - if (grub_biosdisk_call_hook (hook, cd_drive)) - return 1; - } - - /* For floppy disks, we can get the number safely. */ - num_floppies = grub_biosdisk_get_num_floppies (); - for (drive = 0; drive < num_floppies; drive++) - if (grub_biosdisk_call_hook (hook, drive)) - return 1; - return 0; } diff --git a/grub-core/disk/ieee1275/nand.c b/grub-core/disk/ieee1275/nand.c index e9450167e..94d62bc4f 100644 --- a/grub-core/disk/ieee1275/nand.c +++ b/grub-core/disk/ieee1275/nand.c @@ -32,7 +32,8 @@ struct grub_nand_data }; static int -grub_nand_iterate (int (*hook) (const char *name)) +grub_nand_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { auto int dev_iterate (struct grub_ieee1275_devalias *alias); int dev_iterate (struct grub_ieee1275_devalias *alias) @@ -46,6 +47,9 @@ grub_nand_iterate (int (*hook) (const char *name)) return 0; } + if (pull != GRUB_DISK_PULL_NONE) + return 0; + return grub_devalias_iterate (dev_iterate); } diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 7868b14b1..2cd43d80a 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -152,9 +152,14 @@ scan (void) } static int -grub_ofdisk_iterate (int (*hook) (const char *name)) +grub_ofdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { unsigned i; + + if (pull != GRUB_DISK_PULL_NONE) + return 0; + scan (); for (i = 0; i < ARRAY_SIZE (ofdisk_hash); i++) diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index d50f353b1..dca83b7c6 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -133,9 +133,12 @@ fail: static int -grub_loopback_iterate (int (*hook) (const char *name)) +grub_loopback_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_loopback *d; + if (pull != GRUB_DISK_PULL_NONE) + return 0; for (d = loopback_list; d; d = d->next) { if (hook (d->devname)) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 563b49b49..7c19f08de 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -26,12 +26,16 @@ #ifdef GRUB_UTIL #include +#include #endif GRUB_MOD_LICENSE ("GPLv3+"); static struct grub_lvm_vg *vg_list; static int lv_count; +static int scan_depth = 0; + +static int is_lv_readable (struct grub_lvm_lv *lv); /* Go the string STR and return the number after STR. *P will point @@ -95,17 +99,660 @@ grub_lvm_check_flag (char *p, char *str, char *flag) } } -static int -grub_lvm_iterate (int (*hook) (const char *name)) +static struct grub_lvm_lv * +find_lv (const char *name) { struct grub_lvm_vg *vg; + struct grub_lvm_lv *lv = NULL; + for (vg = vg_list; vg; vg = vg->next) + { + if (vg->lvs) + for (lv = vg->lvs; lv; lv = lv->next) + if ((grub_strcmp (lv->fullname, name) == 0 + || grub_strcmp (lv->compatname, name) == 0) + && is_lv_readable (lv)) + return lv; + } + return NULL; +} + +static void +do_lvm_scan (const char *scan_for) +{ + auto int grub_lvm_scan_device (const char *name); + int grub_lvm_scan_device (const char *name) + { + grub_err_t err; + grub_disk_t disk; + grub_uint64_t mda_offset, mda_size; + char buf[GRUB_LVM_LABEL_SIZE]; + char vg_id[GRUB_LVM_ID_STRLEN+1]; + char pv_id[GRUB_LVM_ID_STRLEN+1]; + char *metadatabuf, *p, *q, *vgname; + struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; + struct grub_lvm_pv_header *pvh; + struct grub_lvm_disk_locn *dlocn; + struct grub_lvm_mda_header *mdah; + struct grub_lvm_raw_locn *rlocn; + unsigned int i, j, vgname_len; + struct grub_lvm_vg *vg; + struct grub_lvm_pv *pv; + +#ifdef GRUB_UTIL + grub_util_info ("scanning %s for LVM", name); +#endif + + disk = grub_disk_open (name); + if (!disk) + { + if (grub_errno == GRUB_ERR_OUT_OF_RANGE) + grub_errno = GRUB_ERR_NONE; + return 0; + } + + for (vg = vg_list; vg; vg = vg->next) + for (pv = vg->pvs; pv; pv = pv->next) + if (pv->disk && pv->disk->id == disk->id + && pv->disk->dev->id == disk->dev->id) + { + grub_disk_close (disk); + return 0; + } + + /* Search for label. */ + for (i = 0; i < GRUB_LVM_LABEL_SCAN_SECTORS; i++) + { + err = grub_disk_read (disk, i, 0, sizeof(buf), buf); + if (err) + goto fail; + + if ((! grub_strncmp ((char *)lh->id, GRUB_LVM_LABEL_ID, + sizeof (lh->id))) + && (! grub_strncmp ((char *)lh->type, GRUB_LVM_LVM2_LABEL, + sizeof (lh->type)))) + break; + } + + /* Return if we didn't find a label. */ + if (i == GRUB_LVM_LABEL_SCAN_SECTORS) + { +#ifdef GRUB_UTIL + grub_util_info ("no LVM signature found"); +#endif + goto fail; + } + + pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl)); + + for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++) + { + pv_id[j++] = pvh->pv_uuid[i]; + if ((i != 1) && (i != 29) && (i % 4 == 1)) + pv_id[j++] = '-'; + } + pv_id[j] = '\0'; + + dlocn = pvh->disk_areas_xl; + + dlocn++; + /* Is it possible to have multiple data/metadata areas? I haven't + seen devices that have it. */ + if (dlocn->offset) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "we don't support multiple LVM data areas"); + +#ifdef GRUB_UTIL + grub_util_info ("we don't support multiple LVM data areas\n"); +#endif + goto fail; + } + + dlocn++; + mda_offset = grub_le_to_cpu64 (dlocn->offset); + mda_size = grub_le_to_cpu64 (dlocn->size); + + /* It's possible to have multiple copies of metadata areas, we just use the + first one. */ + + /* Allocate buffer space for the circular worst-case scenario. */ + metadatabuf = grub_malloc (2 * mda_size); + if (! metadatabuf) + goto fail; + + err = grub_disk_read (disk, 0, mda_offset, mda_size, metadatabuf); + if (err) + goto fail2; + + mdah = (struct grub_lvm_mda_header *) metadatabuf; + if ((grub_strncmp ((char *)mdah->magic, GRUB_LVM_FMTT_MAGIC, + sizeof (mdah->magic))) + || (grub_le_to_cpu32 (mdah->version) != GRUB_LVM_FMTT_VERSION)) + { + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "unknown LVM metadata header"); +#ifdef GRUB_UTIL + grub_util_info ("unknown LVM metadata header\n"); +#endif + goto fail2; + } + + rlocn = mdah->raw_locns; + if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) > + grub_le_to_cpu64 (mdah->size)) + { + /* Metadata is circular. Copy the wrap in place. */ + grub_memcpy (metadatabuf + mda_size, + metadatabuf + GRUB_LVM_MDA_HEADER_SIZE, + grub_le_to_cpu64 (rlocn->offset) + + grub_le_to_cpu64 (rlocn->size) - + grub_le_to_cpu64 (mdah->size)); + } + p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); + + while (*q != ' ' && q < metadatabuf + mda_size) + q++; + + if (q == metadatabuf + mda_size) + { +#ifdef GRUB_UTIL + grub_util_info ("error parsing metadata\n"); +#endif + goto fail2; + } + + vgname_len = q - p; + vgname = grub_malloc (vgname_len + 1); + if (!vgname) + goto fail2; + + grub_memcpy (vgname, p, vgname_len); + vgname[vgname_len] = '\0'; + + p = grub_strstr (q, "id = \""); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("couldn't find ID\n"); +#endif + goto fail3; + } + p += sizeof ("id = \"") - 1; + grub_memcpy (vg_id, p, GRUB_LVM_ID_STRLEN); + vg_id[GRUB_LVM_ID_STRLEN] = '\0'; + + for (vg = vg_list; vg; vg = vg->next) + { + if (! grub_memcmp(vg_id, vg->id, GRUB_LVM_ID_STRLEN)) + break; + } + + if (! vg) + { + /* First time we see this volume group. We've to create the + whole volume group structure. */ + vg = grub_malloc (sizeof (*vg)); + if (! vg) + goto fail3; + vg->name = vgname; + grub_memcpy (vg->id, vg_id, GRUB_LVM_ID_STRLEN+1); + + vg->extent_size = grub_lvm_getvalue (&p, "extent_size = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown extent size\n"); +#endif + goto fail4; + } + + vg->lvs = NULL; + vg->pvs = NULL; + + p = grub_strstr (p, "physical_volumes {"); + if (p) + { + p += sizeof ("physical_volumes {") - 1; + + /* Add all the pvs to the volume group. */ + while (1) + { + int s; + while (grub_isspace (*p)) + p++; + + if (*p == '}') + break; + + pv = grub_malloc (sizeof (*pv)); + q = p; + while (*q != ' ') + q++; + + s = q - p; + pv->name = grub_malloc (s + 1); + grub_memcpy (pv->name, p, s); + pv->name[s] = '\0'; + + p = grub_strstr (p, "id = \""); + if (p == NULL) + goto pvs_fail; + p += sizeof("id = \"") - 1; + + grub_memcpy (pv->id, p, GRUB_LVM_ID_STRLEN); + pv->id[GRUB_LVM_ID_STRLEN] = '\0'; + + pv->start = grub_lvm_getvalue (&p, "pe_start = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown pe_start\n"); +#endif + goto pvs_fail; + } + + p = grub_strchr (p, '}'); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("error parsing pe_start\n"); +#endif + goto pvs_fail; + } + p++; + + pv->disk = NULL; + pv->next = vg->pvs; + vg->pvs = pv; + + continue; + pvs_fail: + grub_free (pv->name); + grub_free (pv); + goto fail4; + } + } + + p = grub_strstr (p, "logical_volumes"); + if (p) + { + p += 18; + + /* And add all the lvs to the volume group. */ + while (1) + { + int s; + int skip_lv = 0; + struct grub_lvm_lv *lv; + struct grub_lvm_segment *seg; + int is_pvmove; + + while (grub_isspace (*p)) + p++; + + if (*p == '}') + break; + + lv = grub_malloc (sizeof (*lv)); + + q = p; + while (*q != ' ') + q++; + + s = q - p; + lv->name = grub_strndup (p, s); + if (!lv->name) + goto lvs_fail; + lv->compatname = grub_malloc (vgname_len + 1 + s + 1); + if (!lv->compatname) + goto lvs_fail; + grub_memcpy (lv->compatname, vgname, vgname_len); + lv->compatname[vgname_len] = '-'; + grub_memcpy (lv->compatname + vgname_len + 1, p, s); + lv->compatname[vgname_len + 1 + s] = '\0'; + + { + const char *iptr; + char *optr; + lv->fullname = grub_malloc (sizeof("lvm/") + 2 * vgname_len + + 1 + 2 * s + 1); + if (!lv->fullname) + goto lvs_fail; + + optr = lv->fullname; + grub_memcpy (optr, "lvm/", sizeof ("lvm/") - 1); + optr += sizeof ("lvm/") - 1; + for (iptr = vgname; iptr < vgname + vgname_len; iptr++) + { + *optr++ = *iptr; + if (*iptr == '-') + *optr++ = '-'; + } + *optr++ = '-'; + for (iptr = p; iptr < p + s; iptr++) + { + *optr++ = *iptr; + if (*iptr == '-') + *optr++ = '-'; + } + *optr++ = 0; + } + + lv->size = 0; + + lv->visible = grub_lvm_check_flag (p, "status", "VISIBLE"); + is_pvmove = grub_lvm_check_flag (p, "status", "PVMOVE"); + + lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown segment_count\n"); +#endif + goto lvs_fail; + } + lv->segments = grub_malloc (sizeof (*seg) * lv->segment_count); + seg = lv->segments; + + for (i = 0; i < lv->segment_count; i++) + { + + p = grub_strstr (p, "segment"); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown segment\n"); +#endif + goto lvs_segment_fail; + } + + seg->start_extent = grub_lvm_getvalue (&p, "start_extent = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown start_extent\n"); +#endif + goto lvs_segment_fail; + } + seg->extent_count = grub_lvm_getvalue (&p, "extent_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown extent_count\n"); +#endif + goto lvs_segment_fail; + } + + p = grub_strstr (p, "type = \""); + if (p == NULL) + goto lvs_segment_fail; + p += sizeof("type = \"") - 1; + + lv->size += seg->extent_count * vg->extent_size; + + if (grub_memcmp (p, "striped\"", + sizeof ("striped\"") - 1) == 0) + { + struct grub_lvm_node *stripe; + + seg->type = GRUB_LVM_STRIPED; + seg->node_count = grub_lvm_getvalue (&p, "stripe_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown stripe_count\n"); +#endif + goto lvs_segment_fail; + } + + if (seg->node_count != 1) + seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + + seg->nodes = grub_zalloc (sizeof (*stripe) + * seg->node_count); + stripe = seg->nodes; + + p = grub_strstr (p, "stripes = ["); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown stripes\n"); +#endif + goto lvs_segment_fail2; + } + p += sizeof("stripes = [") - 1; + + for (j = 0; j < seg->node_count; j++) + { + p = grub_strchr (p, '"'); + if (p == NULL) + continue; + q = ++p; + while (*q != '"') + q++; + + s = q - p; + + stripe->name = grub_malloc (s + 1); + if (stripe->name == NULL) + goto lvs_segment_fail2; + + grub_memcpy (stripe->name, p, s); + stripe->name[s] = '\0'; + + stripe->start = grub_lvm_getvalue (&p, ","); + if (p == NULL) + continue; + + stripe++; + } + } + else if (grub_memcmp (p, "mirror\"", sizeof ("mirror\"") - 1) + == 0) + { + seg->type = GRUB_LVM_MIRROR; + seg->node_count = grub_lvm_getvalue (&p, "mirror_count = "); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown mirror_count\n"); +#endif + goto lvs_segment_fail; + } + + seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) + * seg->node_count); + + p = grub_strstr (p, "mirrors = ["); + if (p == NULL) + { +#ifdef GRUB_UTIL + grub_util_info ("unknown mirrors\n"); +#endif + goto lvs_segment_fail2; + } + p += sizeof("mirrors = [") - 1; + + for (j = 0; j < seg->node_count; j++) + { + char *lvname; + + p = grub_strchr (p, '"'); + if (p == NULL) + continue; + q = ++p; + while (*q != '"') + q++; + + s = q - p; + + lvname = grub_malloc (s + 1); + if (lvname == NULL) + goto lvs_segment_fail2; + + grub_memcpy (lvname, p, s); + lvname[s] = '\0'; + seg->nodes[j].name = lvname; + p = q + 1; + } + /* Only first (original) is ok with in progress pvmove. */ + if (is_pvmove) + seg->node_count = 1; + } + else + { +#ifdef GRUB_UTIL + char *p2; + p2 = grub_strchr (p, '"'); + if (p2) + *p2 = 0; + grub_util_info ("unknown LVM type %s\n", p); + if (p2) + *p2 ='"'; +#endif + /* Found a non-supported type, give up and move on. */ + skip_lv = 1; + break; + } + + seg++; + + continue; + lvs_segment_fail2: + grub_free (seg->nodes); + lvs_segment_fail: + goto fail4; + } + + if (p != NULL) + p = grub_strchr (p, '}'); + if (p == NULL) + goto lvs_fail; + p += 3; + + if (skip_lv) + { + grub_free (lv->name); + grub_free (lv); + continue; + } + + lv->number = lv_count++; + lv->vg = vg; + lv->next = vg->lvs; + vg->lvs = lv; + + continue; + lvs_fail: + grub_free (lv->name); + grub_free (lv); + goto fail4; + } + } + + /* Match lvs. */ + { + struct grub_lvm_lv *lv1; + struct grub_lvm_lv *lv2; + for (lv1 = vg->lvs; lv1; lv1 = lv1->next) + for (i = 0; i < lv1->segment_count; i++) + for (j = 0; j < lv1->segments[i].node_count; j++) + { + if (vg->pvs) + for (pv = vg->pvs; pv; pv = pv->next) + { + if (! grub_strcmp (pv->name, + lv1->segments[i].nodes[j].name)) + { + lv1->segments[i].nodes[j].pv = pv; + break; + } + } + if (lv1->segments[i].nodes[j].pv == NULL) + for (lv2 = vg->lvs; lv2; lv2 = lv2->next) + if (grub_strcmp (lv2->name + grub_strlen (vg->name) + 1, + lv1->segments[i].nodes[j].name) == 0) + lv1->segments[i].nodes[j].lv = lv2; + } + + } + + vg->next = vg_list; + vg_list = vg; + } + else + { + grub_free (vgname); + } + + /* Match the device we are currently reading from with the right + PV. */ + if (vg->pvs) + for (pv = vg->pvs; pv; pv = pv->next) + { + if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN)) + { + /* This could happen to LVM on RAID, pv->disk points to the + raid device, we shouldn't change it. */ + if (! pv->disk) + pv->disk = grub_disk_open (name); + break; + } + } + + goto fail2; + + /* Failure path. */ + fail4: + grub_free (vg); + fail3: + grub_free (vgname); + + /* Normal exit path. */ + fail2: + grub_free (metadatabuf); + fail: + grub_disk_close (disk); + if (grub_errno == GRUB_ERR_OUT_OF_RANGE) + grub_errno = GRUB_ERR_NONE; + grub_print_error (); + if (scan_for && find_lv (scan_for)) + return 1; + return 0; + } + + scan_depth++; + grub_device_iterate (&grub_lvm_scan_device); + scan_depth--; +} + +static int +grub_lvm_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) +{ + struct grub_lvm_vg *vg; + unsigned old_count = 0; + if (pull == GRUB_DISK_PULL_RESCAN && scan_depth) + return 0; + + if (pull == GRUB_DISK_PULL_RESCAN) + { + old_count = lv_count; + if (!scan_depth) + do_lvm_scan (NULL); + } + if (pull != GRUB_DISK_PULL_RESCAN && pull != GRUB_DISK_PULL_NONE) + return GRUB_ERR_NONE; for (vg = vg_list; vg; vg = vg->next) { struct grub_lvm_lv *lv; if (vg->lvs) for (lv = vg->lvs; lv; lv = lv->next) - if (lv->visible && hook (lv->name)) - return 1; + if (lv->visible && lv->number >= old_count) + { + if (hook (lv->fullname)) + return 1; + } } return 0; @@ -138,17 +785,23 @@ grub_lvm_memberlist (grub_disk_t disk) static grub_err_t grub_lvm_open (const char *name, grub_disk_t disk) { - struct grub_lvm_vg *vg; struct grub_lvm_lv *lv = NULL; - for (vg = vg_list; vg; vg = vg->next) - { - if (vg->lvs) - for (lv = vg->lvs; lv; lv = lv->next) - if (! grub_strcmp (lv->name, name)) - break; + int explicit = 0; - if (lv) - break; + if (grub_memcmp (name, "lvm/", sizeof ("lvm/") - 1) == 0) + explicit = 1; + + lv = find_lv (name); + + if (! lv && !scan_depth && explicit) + { + do_lvm_scan (name); + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + lv = find_lv (name); } if (! lv) @@ -285,6 +938,49 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector, return grub_error (GRUB_ERR_IO, "unknown LVM segment"); } +static grub_err_t +is_node_readable (const struct grub_lvm_node *node) +{ + /* Check whether we actually know the physical volume we want to + read from. */ + if (node->pv) + return !!(node->pv->disk); + if (node->lv) + return is_lv_readable (node->lv); + return 0; +} + +static int +is_lv_readable (struct grub_lvm_lv *lv) +{ + unsigned int i, j; + + if (!lv) + return 0; + + /* Find the right segment. */ + for (i = 0; i < lv->segment_count; i++) + switch (lv->segments[i].type) + { + case GRUB_LVM_STRIPED: + for (j = 0; j < lv->segments[i].node_count; j++) + if (!is_node_readable (lv->segments[i].nodes + j)) + return 0; + break; + case GRUB_LVM_MIRROR: + for (j = 0; j < lv->segments[i].node_count; j++) + if (is_node_readable (lv->segments[i].nodes + j)) + break; + if (j == lv->segments[i].node_count) + return 0; + default: + return 0; + } + + return 1; +} + + static grub_err_t grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, char *buf) @@ -301,565 +997,6 @@ grub_lvm_write (grub_disk_t disk __attribute ((unused)), return GRUB_ERR_NOT_IMPLEMENTED_YET; } -static int -grub_lvm_scan_device (const char *name) -{ - grub_err_t err; - grub_disk_t disk; - grub_uint64_t mda_offset, mda_size; - char buf[GRUB_LVM_LABEL_SIZE]; - char vg_id[GRUB_LVM_ID_STRLEN+1]; - char pv_id[GRUB_LVM_ID_STRLEN+1]; - char *metadatabuf, *p, *q, *vgname; - struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; - struct grub_lvm_pv_header *pvh; - struct grub_lvm_disk_locn *dlocn; - struct grub_lvm_mda_header *mdah; - struct grub_lvm_raw_locn *rlocn; - unsigned int i, j, vgname_len; - struct grub_lvm_vg *vg; - struct grub_lvm_pv *pv; - -#ifdef GRUB_UTIL - grub_util_info ("scanning %s for LVM", name); -#endif - - disk = grub_disk_open (name); - if (!disk) - { - if (grub_errno == GRUB_ERR_OUT_OF_RANGE) - grub_errno = GRUB_ERR_NONE; - return 0; - } - - /* Search for label. */ - for (i = 0; i < GRUB_LVM_LABEL_SCAN_SECTORS; i++) - { - err = grub_disk_read (disk, i, 0, sizeof(buf), buf); - if (err) - goto fail; - - if ((! grub_strncmp ((char *)lh->id, GRUB_LVM_LABEL_ID, - sizeof (lh->id))) - && (! grub_strncmp ((char *)lh->type, GRUB_LVM_LVM2_LABEL, - sizeof (lh->type)))) - break; - } - - /* Return if we didn't find a label. */ - if (i == GRUB_LVM_LABEL_SCAN_SECTORS) - { -#ifdef GRUB_UTIL - grub_util_info ("no LVM signature found"); -#endif - goto fail; - } - - pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl)); - - for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++) - { - pv_id[j++] = pvh->pv_uuid[i]; - if ((i != 1) && (i != 29) && (i % 4 == 1)) - pv_id[j++] = '-'; - } - pv_id[j] = '\0'; - - dlocn = pvh->disk_areas_xl; - - dlocn++; - /* Is it possible to have multiple data/metadata areas? I haven't - seen devices that have it. */ - if (dlocn->offset) - { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "we don't support multiple LVM data areas"); - -#ifdef GRUB_UTIL - grub_util_info ("we don't support multiple LVM data areas\n"); -#endif - goto fail; - } - - dlocn++; - mda_offset = grub_le_to_cpu64 (dlocn->offset); - mda_size = grub_le_to_cpu64 (dlocn->size); - - /* It's possible to have multiple copies of metadata areas, we just use the - first one. */ - - /* Allocate buffer space for the circular worst-case scenario. */ - metadatabuf = grub_malloc (2 * mda_size); - if (! metadatabuf) - goto fail; - - err = grub_disk_read (disk, 0, mda_offset, mda_size, metadatabuf); - if (err) - goto fail2; - - mdah = (struct grub_lvm_mda_header *) metadatabuf; - if ((grub_strncmp ((char *)mdah->magic, GRUB_LVM_FMTT_MAGIC, - sizeof (mdah->magic))) - || (grub_le_to_cpu32 (mdah->version) != GRUB_LVM_FMTT_VERSION)) - { - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unknown LVM metadata header"); -#ifdef GRUB_UTIL - grub_util_info ("unknown LVM metadata header\n"); -#endif - goto fail2; - } - - rlocn = mdah->raw_locns; - if (grub_le_to_cpu64 (rlocn->offset) + grub_le_to_cpu64 (rlocn->size) > - grub_le_to_cpu64 (mdah->size)) - { - /* Metadata is circular. Copy the wrap in place. */ - grub_memcpy (metadatabuf + mda_size, - metadatabuf + GRUB_LVM_MDA_HEADER_SIZE, - grub_le_to_cpu64 (rlocn->offset) + - grub_le_to_cpu64 (rlocn->size) - - grub_le_to_cpu64 (mdah->size)); - } - p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); - - while (*q != ' ' && q < metadatabuf + mda_size) - q++; - - if (q == metadatabuf + mda_size) - { -#ifdef GRUB_UTIL - grub_util_info ("error parsing metadata\n"); -#endif - goto fail2; - } - - vgname_len = q - p; - vgname = grub_malloc (vgname_len + 1); - if (!vgname) - goto fail2; - - grub_memcpy (vgname, p, vgname_len); - vgname[vgname_len] = '\0'; - - p = grub_strstr (q, "id = \""); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("couldn't find ID\n"); -#endif - goto fail3; - } - p += sizeof ("id = \"") - 1; - grub_memcpy (vg_id, p, GRUB_LVM_ID_STRLEN); - vg_id[GRUB_LVM_ID_STRLEN] = '\0'; - - for (vg = vg_list; vg; vg = vg->next) - { - if (! grub_memcmp(vg_id, vg->id, GRUB_LVM_ID_STRLEN)) - break; - } - - if (! vg) - { - /* First time we see this volume group. We've to create the - whole volume group structure. */ - vg = grub_malloc (sizeof (*vg)); - if (! vg) - goto fail3; - vg->name = vgname; - grub_memcpy (vg->id, vg_id, GRUB_LVM_ID_STRLEN+1); - - vg->extent_size = grub_lvm_getvalue (&p, "extent_size = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown extent size\n"); -#endif - goto fail4; - } - - vg->lvs = NULL; - vg->pvs = NULL; - - p = grub_strstr (p, "physical_volumes {"); - if (p) - { - p += sizeof ("physical_volumes {") - 1; - - /* Add all the pvs to the volume group. */ - while (1) - { - int s; - while (grub_isspace (*p)) - p++; - - if (*p == '}') - break; - - pv = grub_malloc (sizeof (*pv)); - q = p; - while (*q != ' ') - q++; - - s = q - p; - pv->name = grub_malloc (s + 1); - grub_memcpy (pv->name, p, s); - pv->name[s] = '\0'; - - p = grub_strstr (p, "id = \""); - if (p == NULL) - goto pvs_fail; - p += sizeof("id = \"") - 1; - - grub_memcpy (pv->id, p, GRUB_LVM_ID_STRLEN); - pv->id[GRUB_LVM_ID_STRLEN] = '\0'; - - pv->start = grub_lvm_getvalue (&p, "pe_start = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown pe_start\n"); -#endif - goto pvs_fail; - } - - p = grub_strchr (p, '}'); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("error parsing pe_start\n"); -#endif - goto pvs_fail; - } - p++; - - pv->disk = NULL; - pv->next = vg->pvs; - vg->pvs = pv; - - continue; - pvs_fail: - grub_free (pv->name); - grub_free (pv); - goto fail4; - } - } - - p = grub_strstr (p, "logical_volumes"); - if (p) - { - p += 18; - - /* And add all the lvs to the volume group. */ - while (1) - { - int s; - int skip_lv = 0; - struct grub_lvm_lv *lv; - struct grub_lvm_segment *seg; - int is_pvmove; - - while (grub_isspace (*p)) - p++; - - if (*p == '}') - break; - - lv = grub_malloc (sizeof (*lv)); - - q = p; - while (*q != ' ') - q++; - - s = q - p; - lv->name = grub_malloc (vgname_len + 1 + s + 1); - grub_memcpy (lv->name, vgname, vgname_len); - lv->name[vgname_len] = '-'; - grub_memcpy (lv->name + vgname_len + 1, p, s); - lv->name[vgname_len + 1 + s] = '\0'; - - lv->size = 0; - - lv->visible = grub_lvm_check_flag (p, "status", "VISIBLE"); - is_pvmove = grub_lvm_check_flag (p, "status", "PVMOVE"); - - lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown segment_count\n"); -#endif - goto lvs_fail; - } - lv->segments = grub_malloc (sizeof (*seg) * lv->segment_count); - seg = lv->segments; - - for (i = 0; i < lv->segment_count; i++) - { - - p = grub_strstr (p, "segment"); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown segment\n"); -#endif - goto lvs_segment_fail; - } - - seg->start_extent = grub_lvm_getvalue (&p, "start_extent = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown start_extent\n"); -#endif - goto lvs_segment_fail; - } - seg->extent_count = grub_lvm_getvalue (&p, "extent_count = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown extent_count\n"); -#endif - goto lvs_segment_fail; - } - - p = grub_strstr (p, "type = \""); - if (p == NULL) - goto lvs_segment_fail; - p += sizeof("type = \"") - 1; - - lv->size += seg->extent_count * vg->extent_size; - - if (grub_memcmp (p, "striped\"", - sizeof ("striped\"") - 1) == 0) - { - struct grub_lvm_node *stripe; - - seg->type = GRUB_LVM_STRIPED; - seg->node_count = grub_lvm_getvalue (&p, "stripe_count = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown stripe_count\n"); -#endif - goto lvs_segment_fail; - } - - if (seg->node_count != 1) - seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); - - seg->nodes = grub_zalloc (sizeof (*stripe) - * seg->node_count); - stripe = seg->nodes; - - p = grub_strstr (p, "stripes = ["); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown stripes\n"); -#endif - goto lvs_segment_fail2; - } - p += sizeof("stripes = [") - 1; - - for (j = 0; j < seg->node_count; j++) - { - p = grub_strchr (p, '"'); - if (p == NULL) - continue; - q = ++p; - while (*q != '"') - q++; - - s = q - p; - - stripe->name = grub_malloc (s + 1); - if (stripe->name == NULL) - goto lvs_segment_fail2; - - grub_memcpy (stripe->name, p, s); - stripe->name[s] = '\0'; - - stripe->start = grub_lvm_getvalue (&p, ","); - if (p == NULL) - continue; - - stripe++; - } - } - else if (grub_memcmp (p, "mirror\"", sizeof ("mirror\"") - 1) - == 0) - { - seg->type = GRUB_LVM_MIRROR; - seg->node_count = grub_lvm_getvalue (&p, "mirror_count = "); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown mirror_count\n"); -#endif - goto lvs_segment_fail; - } - - seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) - * seg->node_count); - - p = grub_strstr (p, "mirrors = ["); - if (p == NULL) - { -#ifdef GRUB_UTIL - grub_util_info ("unknown mirrors\n"); -#endif - goto lvs_segment_fail2; - } - p += sizeof("mirrors = [") - 1; - - for (j = 0; j < seg->node_count; j++) - { - char *lvname; - - p = grub_strchr (p, '"'); - if (p == NULL) - continue; - q = ++p; - while (*q != '"') - q++; - - s = q - p; - - lvname = grub_malloc (s + 1); - if (lvname == NULL) - goto lvs_segment_fail2; - - grub_memcpy (lvname, p, s); - lvname[s] = '\0'; - seg->nodes[j].name = lvname; - p = q + 1; - } - /* Only first (original) is ok with in progress pvmove. */ - if (is_pvmove) - seg->node_count = 1; - } - else - { -#ifdef GRUB_UTIL - char *p2; - p2 = grub_strchr (p, '"'); - if (p2) - *p2 = 0; - grub_util_info ("unknown LVM type %s\n", p); - if (p2) - *p2 ='"'; -#endif - /* Found a non-supported type, give up and move on. */ - skip_lv = 1; - break; - } - - seg++; - - continue; - lvs_segment_fail2: - grub_free (seg->nodes); - lvs_segment_fail: - goto fail4; - } - - if (p != NULL) - p = grub_strchr (p, '}'); - if (p == NULL) - goto lvs_fail; - p += 3; - - if (skip_lv) - { - grub_free (lv->name); - grub_free (lv); - continue; - } - - lv->number = lv_count++; - lv->vg = vg; - lv->next = vg->lvs; - vg->lvs = lv; - - continue; - lvs_fail: - grub_free (lv->name); - grub_free (lv); - goto fail4; - } - } - - /* Match lvs. */ - { - struct grub_lvm_lv *lv1; - struct grub_lvm_lv *lv2; - for (lv1 = vg->lvs; lv1; lv1 = lv1->next) - for (i = 0; i < lv1->segment_count; i++) - for (j = 0; j < lv1->segments[i].node_count; j++) - { - if (vg->pvs) - for (pv = vg->pvs; pv; pv = pv->next) - { - if (! grub_strcmp (pv->name, - lv1->segments[i].nodes[j].name)) - { - lv1->segments[i].nodes[j].pv = pv; - break; - } - } - if (lv1->segments[i].nodes[j].pv == NULL) - for (lv2 = vg->lvs; lv2; lv2 = lv2->next) - if (grub_strcmp (lv2->name + grub_strlen (vg->name) + 1, - lv1->segments[i].nodes[j].name) == 0) - lv1->segments[i].nodes[j].lv = lv2; - } - - } - - vg->next = vg_list; - vg_list = vg; - } - else - { - grub_free (vgname); - } - - /* Match the device we are currently reading from with the right - PV. */ - if (vg->pvs) - for (pv = vg->pvs; pv; pv = pv->next) - { - if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN)) - { - /* This could happen to LVM on RAID, pv->disk points to the - raid device, we shouldn't change it. */ - if (! pv->disk) - pv->disk = grub_disk_open (name); - break; - } - } - - goto fail2; - - /* Failure path. */ - fail4: - grub_free (vg); - fail3: - grub_free (vgname); - - /* Normal exit path. */ - fail2: - grub_free (metadatabuf); - fail: - grub_disk_close (disk); - if (grub_errno == GRUB_ERR_OUT_OF_RANGE) - grub_errno = GRUB_ERR_NONE; - grub_print_error (); - return 0; -} - static struct grub_disk_dev grub_lvm_dev = { .name = "lvm", @@ -878,13 +1015,6 @@ static struct grub_disk_dev grub_lvm_dev = GRUB_MOD_INIT(lvm) { - grub_device_iterate (&grub_lvm_scan_device); - if (grub_errno) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - } - grub_disk_dev_register (&grub_lvm_dev); } diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index 114ac0d9e..ed570c6a0 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -30,8 +30,12 @@ static char *memdisk_addr; static grub_off_t memdisk_size = 0; static int -grub_memdisk_iterate (int (*hook) (const char *name)) +grub_memdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { + if (pull != GRUB_DISK_PULL_NONE) + return 0; + return hook ("memdisk"); } diff --git a/grub-core/disk/pata.c b/grub-core/disk/pata.c index 95828e8f6..ff6f77366 100644 --- a/grub-core/disk/pata.c +++ b/grub-core/disk/pata.c @@ -486,10 +486,14 @@ grub_pata_open (int id, int devnum, struct grub_ata *ata) } static int -grub_pata_iterate (int (*hook) (int id, int bus)) +grub_pata_iterate (int (*hook) (int id, int bus), + grub_disk_pull_t pull) { struct grub_pata_device *dev; + if (pull != GRUB_DISK_PULL_NONE) + return 0; + for (dev = grub_pata_devices; dev; dev = dev->next) if (hook (GRUB_SCSI_SUBSYSTEM_PATA, dev->port * 2 + dev->device)) return 1; diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index 7c7dbc3dc..5d8326daf 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -33,6 +33,11 @@ GRUB_MOD_LICENSE ("GPLv3+"); static struct grub_raid_array *array_list; grub_raid5_recover_func_t grub_raid5_recover_func; grub_raid6_recover_func_t grub_raid6_recover_func; +static grub_raid_t grub_raid_list; +static int inscnt = 0; + +static struct grub_raid_array * +find_array (const char *name); static char @@ -78,14 +83,98 @@ grub_is_array_readable (struct grub_raid_array *array) return 0; } +static grub_err_t +insert_array (grub_disk_t disk, struct grub_raid_array *new_array, + grub_disk_addr_t start_sector, const char *scanner_name, + grub_raid_t raid __attribute__ ((unused))); + +static int scan_depth = 0; + +static void +scan_devices (const char *arname) +{ + grub_raid_t raid; + + auto int hook (const char *name); + int hook (const char *name) + { + grub_disk_t disk; + struct grub_raid_array array; + struct grub_raid_array *arr; + grub_disk_addr_t start_sector; + + grub_dprintf ("raid", "Scanning for %s RAID devices on disk %s\n", + raid->name, name); +#ifdef GRUB_UTIL + grub_util_info ("Scanning for %s RAID devices on disk %s", + raid->name, name); +#endif + + disk = grub_disk_open (name); + if (!disk) + return 0; + + for (arr = array_list; arr != NULL; arr = arr->next) + { + struct grub_raid_member *m; + for (m = arr->members; m < arr->members + arr->nr_devs; m++) + if (m->device && m->device->id == disk->id + && m->device->dev->id == m->device->dev->id) + { + grub_disk_close (disk); + return 0; + } + } + + if ((disk->total_sectors != GRUB_ULONG_MAX) && + (! raid->detect (disk, &array, &start_sector)) && + (! insert_array (disk, &array, start_sector, raid->name, + raid))) + return 0; + + /* This error usually means it's not raid, no need to display + it. */ + if (grub_errno != GRUB_ERR_OUT_OF_RANGE) + grub_print_error (); + + grub_errno = GRUB_ERR_NONE; + + grub_disk_close (disk); + + if (arname && find_array (arname)) + return 1; + + return 0; + } + + if (scan_depth) + return; + + scan_depth++; + for (raid = grub_raid_list; raid; raid = raid->next) + grub_device_iterate (&hook); + scan_depth--; +} + static int -grub_raid_iterate (int (*hook) (const char *name)) +grub_raid_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { struct grub_raid_array *array; + int islcnt = 0; + + if (pull == GRUB_DISK_PULL_RESCAN) + { + islcnt = inscnt; + scan_devices (NULL); + } + + if (pull != GRUB_DISK_PULL_NONE && pull != GRUB_DISK_PULL_RESCAN) + return 0; for (array = array_list; array != NULL; array = array->next) { - if (grub_is_array_readable (array)) + if (grub_is_array_readable (array) && array->became_readable_at >= islcnt) if (hook (array->name)) return 1; } @@ -134,11 +223,10 @@ ascii2hex (char c) return 0; } -static grub_err_t -grub_raid_open (const char *name, grub_disk_t disk) +static struct grub_raid_array * +find_array (const char *name) { struct grub_raid_array *array; - unsigned n; if (grub_memcmp (name, "mduuid/", sizeof ("mduuid/") - 1) == 0) { @@ -155,7 +243,7 @@ grub_raid_open (const char *name, grub_disk_t disk) if (uuid_len == (unsigned) array->uuid_len && grub_memcmp (uuidbin, array->uuid, uuid_len) == 0) if (grub_is_array_readable (array)) - break; + return array; } } else @@ -163,8 +251,33 @@ grub_raid_open (const char *name, grub_disk_t disk) { if (!grub_strcmp (array->name, name)) if (grub_is_array_readable (array)) - break; + return array; } + return NULL; +} + +static grub_err_t +grub_raid_open (const char *name, grub_disk_t disk) +{ + struct grub_raid_array *array; + unsigned n; + + if (grub_memcmp (name, "md", sizeof ("md") - 1) != 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s", + name); + + array = find_array (name); + + if (! array) + { + scan_devices (name); + if (grub_errno) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + } + array = find_array (name); + } if (!array) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s", @@ -524,6 +637,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, grub_raid_t raid __attribute__ ((unused))) { struct grub_raid_array *array = 0, *p; + int was_readable = 0; /* See whether the device is part of an array we have already seen a device from. */ @@ -534,6 +648,8 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, grub_free (new_array->uuid); array = p; + was_readable = grub_is_array_readable (array); + /* Do some checks before adding the device to the array. */ if (new_array->index >= array->allocated_devs) @@ -736,12 +852,12 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, array->members[new_array->index].device = disk; array->members[new_array->index].start_sector = start_sector; array->nr_devs++; + if (!was_readable && grub_is_array_readable (array)) + array->became_readable_at = inscnt++; return 0; } -static grub_raid_t grub_raid_list; - static void free_array (void) { @@ -772,45 +888,8 @@ free_array (void) void grub_raid_register (grub_raid_t raid) { - auto int hook (const char *name); - int hook (const char *name) - { - grub_disk_t disk; - struct grub_raid_array array; - grub_disk_addr_t start_sector; - - grub_dprintf ("raid", "Scanning for %s RAID devices on disk %s\n", - grub_raid_list->name, name); -#ifdef GRUB_UTIL - grub_util_info ("Scanning for %s RAID devices on disk %s", - grub_raid_list->name, name); -#endif - - disk = grub_disk_open (name); - if (!disk) - return 0; - - if ((disk->total_sectors != GRUB_ULONG_MAX) && - (! grub_raid_list->detect (disk, &array, &start_sector)) && - (! insert_array (disk, &array, start_sector, grub_raid_list->name, - grub_raid_list))) - return 0; - - /* This error usually means it's not raid, no need to display - it. */ - if (grub_errno != GRUB_ERR_OUT_OF_RANGE) - grub_print_error (); - - grub_errno = GRUB_ERR_NONE; - - grub_disk_close (disk); - - return 0; - } - raid->next = grub_raid_list; grub_raid_list = raid; - grub_device_iterate (&hook); } void diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 902564164..610cc4dc5 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -322,7 +322,8 @@ grub_scsi_write12 (grub_disk_t disk, grub_disk_addr_t sector, static int -grub_scsi_iterate (int (*hook) (const char *name)) +grub_scsi_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { grub_scsi_dev_t p; @@ -363,7 +364,7 @@ grub_scsi_iterate (int (*hook) (const char *name)) } for (p = grub_scsi_dev_list; p; p = p->next) - if (p->iterate && (p->iterate) (scsi_iterate)) + if (p->iterate && (p->iterate) (scsi_iterate, pull)) return 1; return 0; diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index 1666197b1..a4c2addf1 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -211,10 +211,14 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno) static int -grub_usbms_iterate (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns)) +grub_usbms_iterate (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns), + grub_disk_pull_t pull) { unsigned i; + if (pull != GRUB_DISK_PULL_NONE) + return 0; + grub_usb_poll_devices (); for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 06eaffc19..5584030bd 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -203,10 +203,12 @@ int grub_disk_dev_iterate (int (*hook) (const char *name)) { grub_disk_dev_t p; + grub_disk_pull_t pull; - for (p = grub_disk_dev_list; p; p = p->next) - if (p->iterate && (p->iterate) (hook)) - return 1; + for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) + for (p = grub_disk_dev_list; p; p = p->next) + if (p->iterate && (p->iterate) (hook, pull)) + return 1; return 0; } diff --git a/grub-core/kern/emu/getroot.c b/grub-core/kern/emu/getroot.c index 6d6c8ef8b..9566317af 100644 --- a/grub-core/kern/emu/getroot.c +++ b/grub-core/kern/emu/getroot.c @@ -648,6 +648,56 @@ grub_guess_root_device (const char *dir) return os_dev; } +#ifdef HAVE_DEVICE_MAPPER + +static int +grub_util_open_dm (const char *os_dev, struct dm_tree **tree, + struct dm_tree_node **node) +{ + uint32_t maj, min; + struct stat st; + + *node = NULL; + *tree = NULL; + + if ((strncmp ("/dev/mapper/", os_dev, 12) != 0)) + return 0; + + if (stat (os_dev, &st) < 0) + return 0; + + *tree = dm_tree_create (); + if (! *tree) + { + grub_printf ("Failed to create tree\n"); + grub_dprintf ("hostdisk", "dm_tree_create failed\n"); + return 0; + } + + maj = major (st.st_rdev); + min = minor (st.st_rdev); + + if (! dm_tree_add_dev (*tree, maj, min)) + { + grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); + dm_tree_free (*tree); + *tree = NULL; + return 0; + } + + *node = dm_tree_find_node (*tree, maj, min); + if (! *node) + { + grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); + dm_tree_free (*tree); + *tree = NULL; + return 0; + } + return 1; +} + +#endif + static int grub_util_is_lvm (const char *os_dev) { @@ -656,40 +706,13 @@ grub_util_is_lvm (const char *os_dev) #ifdef HAVE_DEVICE_MAPPER { - struct dm_tree *tree; - uint32_t maj, min; - struct dm_tree_node *node = NULL; const char *node_uuid; - struct stat st; + struct dm_tree *tree; + struct dm_tree_node *node; - if (stat (os_dev, &st) < 0) + if (!grub_util_open_dm (os_dev, &tree, &node)) return 0; - tree = dm_tree_create (); - if (! tree) - { - grub_printf ("Failed to create tree\n"); - grub_dprintf ("hostdisk", "dm_tree_create failed\n"); - return 0; - } - - maj = major (st.st_rdev); - min = minor (st.st_rdev); - - if (! dm_tree_add_dev (tree, maj, min)) - { - grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); - dm_tree_free (tree); - return 0; - } - - node = dm_tree_find_node (tree, maj, min); - if (! node) - { - grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); - dm_tree_free (tree); - return 0; - } node_uuid = dm_tree_node_get_uuid (node); if (! node_uuid) { @@ -812,11 +835,61 @@ out: } #endif /* __linux__ */ +void +grub_util_pull_device (const char *os_dev) +{ + switch (grub_util_get_dev_abstraction (os_dev)) + { + case GRUB_DEV_ABSTRACTION_LVM: +#ifdef HAVE_DEVICE_MAPPER + { + struct dm_tree *tree; + struct dm_tree_node *node; + struct dm_tree_node *child; + void *handle = NULL; + + if (!grub_util_open_dm (os_dev, &tree, &node)) + return; + + while ((child = dm_tree_next_child (&handle, node, 0))) + { + const struct dm_info *dm = dm_tree_node_get_info (child); + char *subdev; + if (!dm) + continue; + subdev = grub_find_device ("/dev", makedev (dm->major, dm->minor)); + if (subdev) + grub_util_pull_device (subdev); + } + dm_tree_free (tree); + } +#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); + return; + } +} + char * 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: @@ -826,14 +899,10 @@ grub_util_get_grub_dev (const char *os_dev) grub_size_t offset = sizeof ("/dev/mapper/") - 1; len = strlen (os_dev) - offset + 1; - grub_dev = xmalloc (len); + grub_dev = xmalloc (len + sizeof ("lvm/")); - for (i = 0; i < len; i++, offset++) - { - grub_dev[i] = os_dev[offset]; - if (os_dev[offset] == '-' && os_dev[offset + 1] == '-') - offset++; - } + grub_memcpy (grub_dev, "lvm/", sizeof ("lvm/") - 1); + grub_memcpy (grub_dev + sizeof ("lvm/") - 1, os_dev + offset, len); } break; diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index f4af73858..59d7a4a2c 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -214,7 +214,8 @@ find_free_slot (void) } static int -grub_util_biosdisk_iterate (int (*hook) (const char *name)) +grub_util_biosdisk_iterate (int (*hook) (const char *name), + grub_disk_pull_t pull) { unsigned i; diff --git a/util/raid.c b/grub-core/kern/emu/raid.c similarity index 84% rename from util/raid.c rename to grub-core/kern/emu/raid.c index c1c32b959..1e312491b 100644 --- a/util/raid.c +++ b/grub-core/kern/emu/raid.c @@ -21,7 +21,6 @@ #ifdef __linux__ #include #include -#include #include #include @@ -36,7 +35,7 @@ #include char ** -grub_util_raid_getmembers (const char *name) +grub_util_raid_getmembers (const char *name, int bootable) { int fd, ret, i, j; char **devicelist; @@ -53,7 +52,14 @@ grub_util_raid_getmembers (const char *name) if (ret != 0) grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno)); - if (version.major != 0 || version.minor != 90) + 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); diff --git a/include/grub/ata.h b/include/grub/ata.h index 84d5e2d10..6938b6a42 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -22,6 +22,7 @@ #include #include +#include /* XXX: For now this only works on i386. */ #include @@ -192,7 +193,8 @@ typedef struct grub_ata *grub_ata_t; struct grub_ata_dev { /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int (*hook) (int id, int bus)); + int (*iterate) (int (*hook) (int id, int bus), + grub_disk_pull_t pull); /* Open the device named NAME, and set up SCSI. */ grub_err_t (*open) (int id, int bus, struct grub_ata *scsi); diff --git a/include/grub/disk.h b/include/grub/disk.h index c0f2d5994..2b6d02972 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -51,6 +51,14 @@ struct grub_disk; struct grub_disk_memberlist; #endif +typedef enum + { + GRUB_DISK_PULL_NONE, + GRUB_DISK_PULL_REMOVABLE, + GRUB_DISK_PULL_RESCAN, + GRUB_DISK_PULL_MAX + } grub_disk_pull_t; + /* Disk device. */ struct grub_disk_dev { @@ -61,7 +69,8 @@ struct grub_disk_dev enum grub_disk_dev_id id; /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int (*hook) (const char *name)); + int (*iterate) (int (*hook) (const char *name), + grub_disk_pull_t pull); /* Open the device named NAME, and set up DISK. */ grub_err_t (*open) (const char *name, struct grub_disk *disk); diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h index 581ea8056..702903ee6 100644 --- a/include/grub/emu/getroot.h +++ b/include/grub/emu/getroot.h @@ -34,5 +34,8 @@ char *grub_util_get_grub_dev (const char *os_dev); char *grub_make_system_path_relative_to_its_root (const char *path); const char *grub_util_check_block_device (const char *blk_dev); const char *grub_util_check_char_device (const char *blk_dev); +#ifdef __linux__ +char **grub_util_raid_getmembers (const char *name, int bootable); +#endif #endif /* ! GRUB_UTIL_GETROOT_HEADER */ diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 842dff496..803c0f755 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -29,5 +29,6 @@ const char *grub_util_biosdisk_get_osdev (grub_disk_t disk); int grub_util_biosdisk_is_present (const char *name); int grub_util_biosdisk_is_floppy (grub_disk_t disk); grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); +void grub_util_pull_device (const char *osname); #endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */ diff --git a/include/grub/lvm.h b/include/grub/lvm.h index b962dfd6c..b5352c75c 100644 --- a/include/grub/lvm.h +++ b/include/grub/lvm.h @@ -44,6 +44,8 @@ struct grub_lvm_pv { struct grub_lvm_lv { char *name; + char *fullname; + char *compatname; unsigned int number; unsigned int segment_count; grub_uint64_t size; diff --git a/include/grub/raid.h b/include/grub/raid.h index d5853639d..1eb43721a 100644 --- a/include/grub/raid.h +++ b/include/grub/raid.h @@ -42,6 +42,7 @@ struct grub_raid_array int number; /* The device number, taken from md_minor so we are consistent with the device name in Linux. */ + int became_readable_at; int level; /* RAID levels, only 0, 1 or 5 at the moment. */ int layout; /* Layout for RAID 5/6. */ unsigned int total_devs; /* Total number of devices in the array. */ diff --git a/include/grub/scsi.h b/include/grub/scsi.h index f71ef099d..dfee69c62 100644 --- a/include/grub/scsi.h +++ b/include/grub/scsi.h @@ -19,6 +19,8 @@ #ifndef GRUB_SCSI_H #define GRUB_SCSI_H 1 +#include + typedef struct grub_scsi_dev *grub_scsi_dev_t; void grub_scsi_dev_register (grub_scsi_dev_t dev); @@ -50,7 +52,8 @@ grub_make_scsi_id (int subsystem, int bus, int lun) struct grub_scsi_dev { /* Call HOOK with each device name, until HOOK returns non-zero. */ - int (*iterate) (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns)); + int (*iterate) (int NESTED_FUNC_ATTR (*hook) (int id, int bus, int luns), + grub_disk_pull_t pull); /* Open the device named NAME, and set up SCSI. */ grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi); diff --git a/include/grub/util/raid.h b/include/grub/util/raid.h deleted file mode 100644 index 4da5eaaa8..000000000 --- a/include/grub/util/raid.h +++ /dev/null @@ -1,27 +0,0 @@ -/* raid.h - RAID support for GRUB utils. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007 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 . - */ - -#ifndef GRUB_RAID_UTIL_HEADER -#define GRUB_RAID_UTIL_HEADER 1 - -#ifdef __linux__ -char** grub_util_raid_getmembers (const char *name); -#endif - -#endif /* ! GRUB_RAID_UTIL_HEADER */ diff --git a/util/grub-setup.c b/util/grub-setup.c index 7d47fa654..8482e11c9 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #ifdef GRUB_MACHINE_IEEE1275 #include @@ -972,12 +971,12 @@ main (int argc, char *argv[]) int i; if (arguments.device[0] == '/') - devicelist = grub_util_raid_getmembers (arguments.device); + devicelist = grub_util_raid_getmembers (arguments.device, 1); else { char *devname; devname = xasprintf ("/dev/%s", dest_dev); - devicelist = grub_util_raid_getmembers (dest_dev); + devicelist = grub_util_raid_getmembers (dest_dev, 1); free (devname); }