* util/getroot.c (grub_util_get_dm_node_linear_info): Moved from here...
* grub-core/kern/emu/hostdisk.c (grub_util_get_dm_node_linear_info): to here. New return value start. All users updated. Recursively scan linear mappings. * include/grub/emu/hostdisk.h (grub_util_get_dm_node_linear_info): New proto. * grub-core/kern/emu/hostdisk.c (grub_hostdisk_find_partition_start): Use grub_util_get_dm_node_linear_info. * util/getroot.c (convert_system_partition_to_system_disk): Use grub_util_info rather than grub_dprintf. (grub_util_biosdisk_get_grub_dev): Add a new grub_util_info.
This commit is contained in:
parent
60fde14d3e
commit
558d3a6023
4 changed files with 128 additions and 141 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2012-06-07 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* util/getroot.c (grub_util_get_dm_node_linear_info): Moved from here...
|
||||||
|
* grub-core/kern/emu/hostdisk.c (grub_util_get_dm_node_linear_info):
|
||||||
|
to here. New return value start. All users updated.
|
||||||
|
Recursively scan linear mappings.
|
||||||
|
* include/grub/emu/hostdisk.h (grub_util_get_dm_node_linear_info): New
|
||||||
|
proto.
|
||||||
|
* grub-core/kern/emu/hostdisk.c (grub_hostdisk_find_partition_start):
|
||||||
|
Use grub_util_get_dm_node_linear_info.
|
||||||
|
* util/getroot.c (convert_system_partition_to_system_disk): Use
|
||||||
|
grub_util_info rather than grub_dprintf.
|
||||||
|
(grub_util_biosdisk_get_grub_dev): Add a new grub_util_info.
|
||||||
|
|
||||||
2012-06-07 Vladimir Serbinenko <phcoder@gmail.com>
|
2012-06-07 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
Move handling of GRUB_QEMU_OPTS to grub-shell so that make check works.
|
Move handling of GRUB_QEMU_OPTS to grub-shell so that make check works.
|
||||||
|
|
|
@ -420,6 +420,95 @@ grub_util_device_is_mapped (const char *dev)
|
||||||
#endif /* HAVE_DEVICE_MAPPER */
|
#endif /* HAVE_DEVICE_MAPPER */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_DEVICE_MAPPER
|
||||||
|
int
|
||||||
|
grub_util_get_dm_node_linear_info (const char *dev,
|
||||||
|
int *maj, int *min,
|
||||||
|
grub_disk_addr_t *st)
|
||||||
|
{
|
||||||
|
struct dm_task *dmt;
|
||||||
|
void *next = NULL;
|
||||||
|
uint64_t length, start;
|
||||||
|
char *target, *params;
|
||||||
|
char *ptr;
|
||||||
|
int major, minor;
|
||||||
|
int first = 1;
|
||||||
|
grub_disk_addr_t partstart = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
dmt = dm_task_create(DM_DEVICE_TABLE);
|
||||||
|
if (!dmt)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (! (first ? dm_task_set_name (dmt, dev)
|
||||||
|
: dm_task_set_major_minor (dmt, major, minor, 0)))
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dm_task_no_open_count(dmt);
|
||||||
|
if (!dm_task_run(dmt))
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next = dm_get_next_target(dmt, next, &start, &length,
|
||||||
|
&target, ¶ms);
|
||||||
|
if (grub_strcmp (target, "linear") != 0)
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
major = grub_strtoul (params, &ptr, 10);
|
||||||
|
if (grub_errno)
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (*ptr != ':')
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ptr++;
|
||||||
|
minor = grub_strtoul (ptr, &ptr, 10);
|
||||||
|
if (grub_errno)
|
||||||
|
{
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ptr != ' ')
|
||||||
|
{
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ptr++;
|
||||||
|
partstart += grub_strtoull (ptr, &ptr, 10);
|
||||||
|
if (grub_errno)
|
||||||
|
{
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dm_task_destroy (dmt);
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
if (first)
|
||||||
|
return 0;
|
||||||
|
if (maj)
|
||||||
|
*maj = major;
|
||||||
|
if (min)
|
||||||
|
*min = minor;
|
||||||
|
if (st)
|
||||||
|
*st = partstart;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
|
|
||||||
|
@ -508,71 +597,10 @@ grub_hostdisk_find_partition_start (const char *dev)
|
||||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||||
|
|
||||||
# ifdef HAVE_DEVICE_MAPPER
|
# ifdef HAVE_DEVICE_MAPPER
|
||||||
if (grub_util_device_is_mapped (dev)) {
|
|
||||||
struct dm_task *task = NULL;
|
|
||||||
grub_uint64_t start, length;
|
|
||||||
char *target_type, *params, *space;
|
|
||||||
grub_disk_addr_t partition_start;
|
grub_disk_addr_t partition_start;
|
||||||
|
if (grub_util_device_is_mapped (dev)
|
||||||
/* If any device-mapper operation fails, we fall back silently to
|
&& grub_util_get_dm_node_linear_info (dev, 0, 0, &partition_start))
|
||||||
HDIO_GETGEO. */
|
|
||||||
task = dm_task_create (DM_DEVICE_TABLE);
|
|
||||||
if (! task)
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "dm_task_create failed\n");
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! dm_task_set_name (task, dev))
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "dm_task_set_name failed\n");
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! dm_task_run (task))
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "dm_task_run failed\n");
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
dm_get_next_target (task, NULL, &start, &length, &target_type, ¶ms);
|
|
||||||
if (! target_type)
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "no dm target\n");
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
if (strcmp (target_type, "linear") != 0)
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "ignoring dm target %s (not linear)\n",
|
|
||||||
target_type);
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
if (! params)
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "no dm params\n");
|
|
||||||
goto devmapper_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The params string for a linear target looks like this:
|
|
||||||
DEVICE-NAME START-SECTOR
|
|
||||||
Parse this out. */
|
|
||||||
space = strchr (params, ' ');
|
|
||||||
if (! space)
|
|
||||||
goto devmapper_fail;
|
|
||||||
errno = 0;
|
|
||||||
partition_start = strtoull (space + 1, NULL, 10);
|
|
||||||
if (errno == 0)
|
|
||||||
{
|
|
||||||
grub_dprintf ("hostdisk", "dm %s starts at %llu\n",
|
|
||||||
dev, (unsigned long long) partition_start);
|
|
||||||
dm_task_destroy (task);
|
|
||||||
return partition_start;
|
return partition_start;
|
||||||
}
|
|
||||||
|
|
||||||
devmapper_fail:
|
|
||||||
if (task)
|
|
||||||
dm_task_destroy (task);
|
|
||||||
}
|
|
||||||
# endif /* HAVE_DEVICE_MAPPER */
|
# endif /* HAVE_DEVICE_MAPPER */
|
||||||
|
|
||||||
fd = open (dev, O_RDONLY);
|
fd = open (dev, O_RDONLY);
|
||||||
|
|
|
@ -65,4 +65,11 @@ grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize);
|
||||||
char *
|
char *
|
||||||
grub_util_get_os_disk (const char *os_dev);
|
grub_util_get_os_disk (const char *os_dev);
|
||||||
|
|
||||||
|
#ifdef HAVE_DEVICE_MAPPER
|
||||||
|
int
|
||||||
|
grub_util_get_dm_node_linear_info (const char *dev,
|
||||||
|
int *maj, int *min,
|
||||||
|
grub_disk_addr_t *st);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
|
#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
|
||||||
|
|
|
@ -1575,69 +1575,6 @@ grub_util_pull_device (const char *os_dev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DEVICE_MAPPER
|
|
||||||
static int
|
|
||||||
grub_util_get_dm_node_linear_info (const char *dev,
|
|
||||||
int *maj, int *min)
|
|
||||||
{
|
|
||||||
struct dm_task *dmt;
|
|
||||||
void *next = NULL;
|
|
||||||
uint64_t length, start;
|
|
||||||
char *target, *params;
|
|
||||||
char *ptr;
|
|
||||||
int major, minor;
|
|
||||||
|
|
||||||
dmt = dm_task_create(DM_DEVICE_TABLE);
|
|
||||||
if (!dmt)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!dm_task_set_name(dmt, dev))
|
|
||||||
{
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
dm_task_no_open_count(dmt);
|
|
||||||
if (!dm_task_run(dmt))
|
|
||||||
{
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
next = dm_get_next_target(dmt, next, &start, &length,
|
|
||||||
&target, ¶ms);
|
|
||||||
if (grub_strcmp (target, "linear") != 0)
|
|
||||||
{
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
major = grub_strtoul (params, &ptr, 10);
|
|
||||||
if (grub_errno)
|
|
||||||
{
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (*ptr != ':')
|
|
||||||
{
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
minor = grub_strtoul (ptr, 0, 10);
|
|
||||||
if (grub_errno)
|
|
||||||
{
|
|
||||||
grub_errno = GRUB_ERR_NONE;
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (maj)
|
|
||||||
*maj = major;
|
|
||||||
if (min)
|
|
||||||
*min = minor;
|
|
||||||
dm_task_destroy (dmt);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
grub_util_biosdisk_is_floppy (grub_disk_t disk)
|
grub_util_biosdisk_is_floppy (grub_disk_t disk)
|
||||||
{
|
{
|
||||||
|
@ -1882,7 +1819,7 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
||||||
tree = dm_tree_create ();
|
tree = dm_tree_create ();
|
||||||
if (! tree)
|
if (! tree)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "dm_tree_create failed\n");
|
grub_util_info ("dm_tree_create failed");
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1890,26 +1827,26 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
||||||
min = minor (st->st_rdev);
|
min = minor (st->st_rdev);
|
||||||
if (! dm_tree_add_dev (tree, maj, min))
|
if (! dm_tree_add_dev (tree, maj, min))
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
|
grub_util_info ("dm_tree_add_dev failed");
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = dm_tree_find_node (tree, maj, min);
|
node = dm_tree_find_node (tree, maj, min);
|
||||||
if (! node)
|
if (! node)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
|
grub_util_info ("dm_tree_find_node failed");
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
node_uuid = dm_tree_node_get_uuid (node);
|
node_uuid = dm_tree_node_get_uuid (node);
|
||||||
if (! node_uuid)
|
if (! node_uuid)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s has no DM uuid\n", path);
|
grub_util_info ("%s has no DM uuid", path);
|
||||||
node = NULL;
|
node = NULL;
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
if (strncmp (node_uuid, "LVM-", 4) == 0)
|
if (strncmp (node_uuid, "LVM-", 4) == 0)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s is an LVM\n", path);
|
grub_util_info ("%s is an LVM", path);
|
||||||
node = NULL;
|
node = NULL;
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
|
@ -1919,7 +1856,7 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
||||||
linear mappings so are handled by
|
linear mappings so are handled by
|
||||||
grub_util_get_dm_node_linear_info. Multipath disks are not
|
grub_util_get_dm_node_linear_info. Multipath disks are not
|
||||||
linear mappings and must be handled specially. */
|
linear mappings and must be handled specially. */
|
||||||
grub_dprintf ("hostdisk", "%s is a multipath disk\n", path);
|
grub_util_info ("%s is a multipath disk", path);
|
||||||
mapper_name = dm_tree_node_get_name (node);
|
mapper_name = dm_tree_node_get_name (node);
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
|
@ -1927,11 +1864,11 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
||||||
{
|
{
|
||||||
int major, minor;
|
int major, minor;
|
||||||
const char *node_name;
|
const char *node_name;
|
||||||
grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
|
grub_util_info ("%s is not DM-RAID", path);
|
||||||
|
|
||||||
if ((node_name = dm_tree_node_get_name (node))
|
if ((node_name = dm_tree_node_get_name (node))
|
||||||
&& grub_util_get_dm_node_linear_info (node_name,
|
&& grub_util_get_dm_node_linear_info (node_name,
|
||||||
&major, &minor))
|
&major, &minor, 0))
|
||||||
{
|
{
|
||||||
*is_part = 1;
|
*is_part = 1;
|
||||||
if (tree)
|
if (tree)
|
||||||
|
@ -1953,24 +1890,24 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
||||||
child = dm_tree_next_child (&handle, node, 0);
|
child = dm_tree_next_child (&handle, node, 0);
|
||||||
if (! child)
|
if (! child)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s has no DM children\n", path);
|
grub_util_info ("%s has no DM children", path);
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
child_uuid = dm_tree_node_get_uuid (child);
|
child_uuid = dm_tree_node_get_uuid (child);
|
||||||
if (! child_uuid)
|
if (! child_uuid)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s child has no DM uuid\n", path);
|
grub_util_info ("%s child has no DM uuid", path);
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
else if (strncmp (child_uuid, "DMRAID-", 7) != 0)
|
else if (strncmp (child_uuid, "DMRAID-", 7) != 0)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s child is not DM-RAID\n", path);
|
grub_util_info ("%s child is not DM-RAID", path);
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
child_name = dm_tree_node_get_name (child);
|
child_name = dm_tree_node_get_name (child);
|
||||||
if (! child_name)
|
if (! child_name)
|
||||||
{
|
{
|
||||||
grub_dprintf ("hostdisk", "%s child has no DM name\n", path);
|
grub_util_info ("%s child has no DM name", path);
|
||||||
goto devmapper_out;
|
goto devmapper_out;
|
||||||
}
|
}
|
||||||
mapper_name = child_name;
|
mapper_name = child_name;
|
||||||
|
@ -1981,7 +1918,7 @@ devmapper_out:
|
||||||
/* This is a DM-RAID disk, not a partition. */
|
/* This is a DM-RAID disk, not a partition. */
|
||||||
mapper_name = dm_tree_node_get_name (node);
|
mapper_name = dm_tree_node_get_name (node);
|
||||||
if (! mapper_name)
|
if (! mapper_name)
|
||||||
grub_dprintf ("hostdisk", "%s has no DM name\n", path);
|
grub_util_info ("%s has no DM name", path);
|
||||||
}
|
}
|
||||||
char *ret;
|
char *ret;
|
||||||
if (mapper_name)
|
if (mapper_name)
|
||||||
|
@ -2238,6 +2175,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
||||||
|
|
||||||
drive = find_system_device (os_dev, &st, 1, 1);
|
drive = find_system_device (os_dev, &st, 1, 1);
|
||||||
sys_disk = convert_system_partition_to_system_disk (os_dev, &st, &is_part);
|
sys_disk = convert_system_partition_to_system_disk (os_dev, &st, &is_part);
|
||||||
|
grub_util_info ("%s is a parent of %s", sys_disk, os_dev);
|
||||||
if (grub_strcmp (os_dev, sys_disk) == 0)
|
if (grub_strcmp (os_dev, sys_disk) == 0)
|
||||||
{
|
{
|
||||||
free (sys_disk);
|
free (sys_disk);
|
||||||
|
|
Loading…
Reference in a new issue