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