Skip to contentSkip to conversation

ieee1275/powerpc: implement ofpath to enable hint feature for FC and dm devices

PATCH In review Diego Domingos 3 participants 5 messages Nov 20, 2020 – Nov 16, 2021

lore
Share & tools
lore
#0 lore raw

cover ieee1275/powerpc: implement ofpath to enable hint feature for FC and dm devices

The grub-ofpathname and hint feature for ieee1275 are not working since there is no code implemented to get the information needed about fibre channel devices and device mapper.

This patch series implements the codes for both groups of devices and with them we can get the --hint-ieee1275 working properly.

#1 lore raw

PATCH 1/2 ieee1275/powerpc: implements fibre channel discovery for ofpathname

From: Diego Domingos <[email protected]>

grub-ofpathname doesn't work with fibre channel because there is no function currently implemented for it.
This patch enables it by prividing a function that looks for the port name, building the entire path for OF devices.

---
 grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
grub-core/osdep/linux/ofpath.c +49 -0
index a6153d359..0f5d54e9f 100644
@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
   return ret;
 }
 
+
+static void
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
+{
+  char *bname, *basepath, *p;
+  int fd;
+
+  bname = xmalloc(sizeof(char)*150);
+  basepath = xmalloc(strlen(path));
+
+  /* Generate the path to get port name information from the drive */
+  strncpy(basepath,path,subpath-path);
+  basepath[subpath-path-1] = '\0';
+  p = get_basename(basepath);
+  snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p);
+
+  /* Read the information from the port name */
+  fd = open (bname, O_RDONLY);
+  if (fd < 0)
+    grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno));
+
+  if (read(fd,port_name,sizeof(char)*19) < 0)
+    grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno));
+
+  sscanf(port_name,"0x%s",port_name);
+  
+  close(fd);
+
+  free(bname);
+  free(basepath);
+}
+
 #ifdef __sparc__
 static char *
 of_path_of_nvme(const char *sys_devname __attribute__((unused)),
@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
   digit_string = trailing_digits (device);
   if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
     {
+      if(strstr(of_path,"vfc-client"))
+      {
+	char * port_name = xmalloc(sizeof(char)*17);
+	of_fc_port_name(sysfs_path, p, port_name);
+	
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
+	free(port_name);
+      }
+      else
+      {
       unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
       if (*digit_string == '\0')
 	{
@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
 	  snprintf(disk, sizeof (disk),
 		   "/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
 	}
+	}
+    } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){
+	char * port_name = xmalloc(sizeof(char)*17);
+	of_fc_port_name(sysfs_path, p, port_name);
+	
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
+	free(port_name);
     }
   else
     {
Signature · 1 line
2.21.3
#2 lore raw

PATCH 2/2 ieee1275/powerpc: enables device mapper discovery

In reply to Diego Domingos

From: Diego Domingos <[email protected]>

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.

---
 grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
grub-core/osdep/linux/ofpath.c +63 -1
index 0f5d54e9f..cc849d9c9 100644
@@ -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);
+    free(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 (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);
Signature · 1 line
2.21.3
Tested-by on the v1 series
#3 lore raw
In reply to Diego Domingos

Hello Diego,

Quoted 4 lines · Diego Domingos

The grub-ofpathname and hint feature for ieee1275 are not working since there is no code implemented to get the information needed about fibre channel devices and device mapper.

This patch series implements the codes for both groups of devices and with them we can get the --hint-ieee1275 working properly.

We are using these patches in Fedora and RHEL for some time and it does solve the mentioned issues.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
Tested-by
#4 lore raw
Quoted 5 lines · Javier Martinez Canillas

Hello Diego,

Quoted 2 lines · Diego Domingos

The grub-ofpathname and hint feature for ieee1275 are not working since there is no code implemented to get the information needed about fibre channel devices and device mapper.

Quoted 7 lines
Quoted 2 lines

This patch series implements the codes for both groups of devices and with them we can get the --hint-ieee1275 working properly.

We are using these patches in Fedora and RHEL for some time and it does solve the mentioned issues.

Same with SUSE/openSUSE.

Thanks,
Michael

Quoted 12 lines

Best regards,

Signature · 9 lines
Javier Martinez Canillas
Linux Engineering
Red Hat


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel