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