All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avnish Chouhan <avnish@linux.ibm.com>
To: grub-devel@gnu.org
Cc: daniel.kiper@oracle.com, brking@linux.ibm.com,
	meghanaprakash@in.ibm.com,  Avnish Chouhan <avnish@linux.ibm.com>,
	Diego Domingos <diegodo@br.ibm.com>
Subject: [PATCH v3 2/6] ieee1275/powerpc: enables device mapper discovery
Date: Thu,  6 Jun 2024 18:07:23 +0530	[thread overview]
Message-ID: <20240606123727.38614-3-avnish@linux.ibm.com> (raw)
In-Reply-To: <20240606123727.38614-1-avnish@linux.ibm.com>

This patch enables the device mapper discovery on ofpath.c. Currently,
when we are dealing with a device like /dev/dm-* the ofpath returns null
since there is no function implemented to handle this case.

This patch implements a function that will look into /sys/block/dm-*
devices and search recursively inside slaves directory to find the root
disk.

Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
---
 grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index 0f5d54e9f2d..cc849d9c94c 100644
--- a/grub-core/osdep/linux/ofpath.c
+++ b/grub-core/osdep/linux/ofpath.c
@@ -37,6 +37,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
+#include <dirent.h>
 
 #ifdef __sparc__
 typedef enum
@@ -755,13 +756,74 @@ strip_trailing_digits (const char *p)
   return new;
 }
 
+static char *
+get_slave_from_dm (const char * device)
+{
+  char *curr_device, *tmp;
+  char *directory;
+  char *ret = NULL;
+  directory = grub_strdup (device);
+  tmp = get_basename (directory);
+  curr_device = grub_strdup (tmp);
+  *tmp = '\0';
+
+  /* Recursively check for slaves devices so we can find the root device */
+  while ((curr_device[0] == 'd') && (curr_device[1] == 'm') && (curr_device[2] == '-'))
+    {
+      DIR *dp;
+      struct dirent *ep;
+      char* device_path;
+      device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device);
+      dp = opendir (device_path);
+
+      if (dp != NULL)
+        {
+          ep = readdir (dp);
+
+          while (ep != NULL)
+            {
+	       /* avoid some system directories */
+              if (!strcmp(ep->d_name,"."))
+                goto next_dir;
+              if (!strcmp(ep->d_name,".."))
+                goto next_dir;
+
+	       free (curr_device);
+	       free (ret);
+	       curr_device = grub_strdup (ep->d_name);
+	       ret = grub_xasprintf ("%s%s", directory, curr_device);
+	       break;
+
+              next_dir:
+              ep = readdir (dp);
+              continue;
+            }
+          closedir (dp);
+        }
+      else
+        grub_util_warn (_("cannot open directory `%s'"), device_path);
+      free (device_path);
+    }
+  free (directory);
+  free (curr_device);
+
+  return ret;
+}
+
 char *
 grub_util_devname_to_ofpath (const char *sys_devname)
 {
-  char *name_buf, *device, *devnode, *devicenode, *ofpath;
+  char *name_buf, *device, *devnode, *devicenode, *ofpath, *realname;
 
   name_buf = xrealpath (sys_devname);
 
+  realname = get_slave_from_dm (name_buf);
+  if (realname)
+    {
+      free (name_buf);
+      name_buf = realname;
+    }
+
   device = get_basename (name_buf);
   devnode = strip_trailing_digits (name_buf);
   devicenode = strip_trailing_digits (device);

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2024-06-06 12:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 12:37 [PATCH v3 0/6] NVMeoFC support on Grub Avnish Chouhan
2024-06-06 12:37 ` [PATCH v3 1/6] ieee1275/powerpc: implements fibre channel discovery for ofpathname Avnish Chouhan
2024-06-26 10:17   ` Michael Chang via Grub-devel
2024-06-06 12:37 ` Avnish Chouhan [this message]
2024-06-06 15:34   ` [PATCH v3 2/6] ieee1275/powerpc: enables device mapper discovery Vladimir 'phcoder' Serbinenko
2024-06-07  8:34     ` avnish
2024-06-07  9:34       ` Vladimir 'phcoder' Serbinenko
2024-06-06 12:37 ` [PATCH v3 3/6] ieee1275: implement FCP methods for WWPN and LUNs Avnish Chouhan
2024-07-01  7:34   ` Michael Chang via Grub-devel
2024-07-01 10:40     ` avnish
2024-06-06 12:37 ` [PATCH v3 4/6] ieee1275: change the logic of ieee1275_get_devargs() Avnish Chouhan
2024-06-06 12:37 ` [PATCH v3 5/6] ieee1275: add support for NVMeoFC Avnish Chouhan
2024-06-06 12:37 ` [PATCH v3 6/6] ieee1275: ofpath enable NVMeoF logical device translate Avnish Chouhan
     [not found] <mailman.2999.1717752901.1278.grub-devel@gnu.org>
2024-06-20  9:44 ` [PATCH v3 2/6] ieee1275/powerpc: enables device mapper discovery avnish
2024-06-20 10:37   ` Vladimir 'phcoder' Serbinenko
2024-06-25  4:31   ` Michael Chang via Grub-devel
2024-06-25 10:42     ` avnish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240606123727.38614-3-avnish@linux.ibm.com \
    --to=avnish@linux.ibm.com \
    --cc=brking@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=diegodo@br.ibm.com \
    --cc=grub-devel@gnu.org \
    --cc=meghanaprakash@in.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.