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