|
|
dbe756 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
dbe756 |
From: Diego Domingos <diegodo@br.ibm.com>
|
|
|
dbe756 |
Date: Mon, 14 Dec 2020 17:47:16 +0100
|
|
|
dbe756 |
Subject: [PATCH] ieee1275/powerpc: enables device mapper discovery
|
|
|
dbe756 |
|
|
|
dbe756 |
this patch enables the device mapper discovery on ofpath.c. Currently,
|
|
|
dbe756 |
when we are dealing with a device like /dev/dm-* the ofpath returns null
|
|
|
dbe756 |
since there is no function implemented to handle this case.
|
|
|
dbe756 |
|
|
|
dbe756 |
This patch implements a function that will look into /sys/block/dm-*
|
|
|
dbe756 |
devices and search recursively inside slaves directory to find the root
|
|
|
dbe756 |
disk.
|
|
|
dbe756 |
|
|
|
dbe756 |
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
|
|
dbe756 |
---
|
|
|
dbe756 |
grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++++++++++-
|
|
|
dbe756 |
1 file changed, 63 insertions(+), 1 deletion(-)
|
|
|
dbe756 |
|
|
|
dbe756 |
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
|
|
030dc3 |
index 0f5d54e9f2d..cc849d9c94c 100644
|
|
|
dbe756 |
--- a/grub-core/osdep/linux/ofpath.c
|
|
|
dbe756 |
+++ b/grub-core/osdep/linux/ofpath.c
|
|
|
dbe756 |
@@ -37,6 +37,7 @@
|
|
|
dbe756 |
#include <fcntl.h>
|
|
|
dbe756 |
#include <errno.h>
|
|
|
dbe756 |
#include <ctype.h>
|
|
|
dbe756 |
+#include <dirent.h>
|
|
|
dbe756 |
|
|
|
dbe756 |
#ifdef __sparc__
|
|
|
dbe756 |
typedef enum
|
|
|
dbe756 |
@@ -755,13 +756,74 @@ strip_trailing_digits (const char *p)
|
|
|
dbe756 |
return new;
|
|
|
dbe756 |
}
|
|
|
dbe756 |
|
|
|
dbe756 |
+static char *
|
|
|
dbe756 |
+get_slave_from_dm(const char * device){
|
|
|
dbe756 |
+ char *curr_device, *tmp;
|
|
|
dbe756 |
+ char *directory;
|
|
|
dbe756 |
+ char *ret = NULL;
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ directory = grub_strdup (device);
|
|
|
dbe756 |
+ tmp = get_basename(directory);
|
|
|
dbe756 |
+ curr_device = grub_strdup (tmp);
|
|
|
dbe756 |
+ *tmp = '\0';
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ /* Recursively check for slaves devices so we can find the root device */
|
|
|
dbe756 |
+ while ((curr_device[0] == 'd') && (curr_device[1] == 'm') && (curr_device[2] == '-')){
|
|
|
dbe756 |
+ DIR *dp;
|
|
|
dbe756 |
+ struct dirent *ep;
|
|
|
dbe756 |
+ char* device_path;
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device);
|
|
|
dbe756 |
+ dp = opendir(device_path);
|
|
|
dbe756 |
+ free(device_path);
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ if (dp != NULL)
|
|
|
dbe756 |
+ {
|
|
|
dbe756 |
+ ep = readdir (dp);
|
|
|
dbe756 |
+ while (ep != NULL){
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ /* avoid some system directories */
|
|
|
dbe756 |
+ if (!strcmp(ep->d_name,"."))
|
|
|
dbe756 |
+ goto next_dir;
|
|
|
dbe756 |
+ if (!strcmp(ep->d_name,".."))
|
|
|
dbe756 |
+ goto next_dir;
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ free (curr_device);
|
|
|
dbe756 |
+ free (ret);
|
|
|
dbe756 |
+ curr_device = grub_strdup (ep->d_name);
|
|
|
dbe756 |
+ ret = grub_xasprintf ("%s%s", directory, curr_device);
|
|
|
dbe756 |
+ break;
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ next_dir:
|
|
|
dbe756 |
+ ep = readdir (dp);
|
|
|
dbe756 |
+ continue;
|
|
|
dbe756 |
+ }
|
|
|
dbe756 |
+ closedir (dp);
|
|
|
dbe756 |
+ }
|
|
|
dbe756 |
+ else
|
|
|
dbe756 |
+ grub_util_warn (_("cannot open directory `%s'"), device_path);
|
|
|
dbe756 |
+ }
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ free (directory);
|
|
|
dbe756 |
+ free (curr_device);
|
|
|
dbe756 |
+
|
|
|
dbe756 |
+ return ret;
|
|
|
dbe756 |
+}
|
|
|
dbe756 |
+
|
|
|
dbe756 |
char *
|
|
|
dbe756 |
grub_util_devname_to_ofpath (const char *sys_devname)
|
|
|
dbe756 |
{
|
|
|
dbe756 |
- char *name_buf, *device, *devnode, *devicenode, *ofpath;
|
|
|
dbe756 |
+ char *name_buf, *device, *devnode, *devicenode, *ofpath, *realname;
|
|
|
dbe756 |
|
|
|
dbe756 |
name_buf = xrealpath (sys_devname);
|
|
|
dbe756 |
|
|
|
dbe756 |
+ realname = get_slave_from_dm (name_buf);
|
|
|
dbe756 |
+ if (realname)
|
|
|
dbe756 |
+ {
|
|
|
dbe756 |
+ free (name_buf);
|
|
|
dbe756 |
+ name_buf = realname;
|
|
|
dbe756 |
+ }
|
|
|
dbe756 |
+
|
|
|
dbe756 |
device = get_basename (name_buf);
|
|
|
dbe756 |
devnode = strip_trailing_digits (name_buf);
|
|
|
dbe756 |
devicenode = strip_trailing_digits (device);
|