dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0446-ieee1275-powerpc-implements-fibre-channel-discovery-.patch

110f85
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
110f85
From: Diego Domingos <diegodo@br.ibm.com>
110f85
Date: Wed, 24 Jun 2020 08:17:18 -0400
110f85
Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for
110f85
 ofpathname
110f85
110f85
grub-ofpathname doesn't work with fibre channel because there is no
110f85
function currently implemented for it.
110f85
This patch enables it by prividing a function that looks for the port
110f85
name, building the entire path for OF devices.
110f85
---
110f85
 grub-core/osdep/linux/ofpath.c | 52 +++++++++++++++++++++++++++++++++++++++++-
110f85
 1 file changed, 51 insertions(+), 1 deletion(-)
110f85
110f85
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
110f85
index 8f24bc9e897..4334b19cace 100644
110f85
--- a/grub-core/osdep/linux/ofpath.c
110f85
+++ b/grub-core/osdep/linux/ofpath.c
110f85
@@ -300,6 +300,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
110f85
   return ret;
110f85
 }
110f85
 
110f85
+
110f85
+static void
110f85
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
110f85
+{
110f85
+  char *bname, *basepath, *p;
110f85
+  int fd;
110f85
+
110f85
+  bname = xmalloc(sizeof(char)*150);
110f85
+  basepath = xmalloc(strlen(path));
110f85
+
110f85
+  /* Generate the path to get port name information from the drive */
110f85
+  strncpy(basepath,path,subpath-path);
110f85
+  basepath[subpath-path-1] = '\0';
110f85
+  p = get_basename(basepath);
110f85
+  snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p);
110f85
+
110f85
+  /* Read the information from the port name */
110f85
+  fd = open (bname, O_RDONLY);
110f85
+  if (fd < 0)
110f85
+    grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno));
110f85
+
110f85
+  if (read(fd,port_name,sizeof(char)*19) < 0)
110f85
+    grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno));
110f85
+
110f85
+  sscanf(port_name,"0x%s",port_name);
110f85
+  
110f85
+  close(fd);
110f85
+
110f85
+  free(bname);
110f85
+  free(basepath);
110f85
+}
110f85
+
110f85
 static int
110f85
 vendor_is_ATA(const char *path)
110f85
 {
110f85
@@ -404,7 +436,7 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
110f85
     }
110f85
 
110f85
   of_path = find_obppath(sysfs_path);
110f85
-  free (sysfs_path);
110f85
+
110f85
   if (!of_path)
110f85
     return NULL;
110f85
 
110f85
@@ -419,6 +451,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
110f85
   digit_string = trailing_digits (device);
110f85
   if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
110f85
     {
110f85
+      if(strstr(of_path,"vfc-client"))
110f85
+      {
110f85
+	char * port_name = xmalloc(sizeof(char)*17);
110f85
+	of_fc_port_name(sysfs_path, p, port_name);
110f85
+	
110f85
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
110f85
+	free(port_name);
110f85
+      }
110f85
+      else
110f85
+      {
110f85
       unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
110f85
       if (*digit_string == '\0')
110f85
 	{
110f85
@@ -432,6 +474,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
110f85
 	  snprintf(disk, sizeof (disk),
110f85
 		   "/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
110f85
 	}
110f85
+	}
110f85
+    } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){
110f85
+	char * port_name = xmalloc(sizeof(char)*17);
110f85
+	of_fc_port_name(sysfs_path, p, port_name);
110f85
+	
110f85
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
110f85
+	free(port_name);
110f85
     }
110f85
   else
110f85
     {
110f85
@@ -482,6 +531,7 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
110f85
             }
110f85
         }
110f85
     }
110f85
+  free (sysfs_path);
110f85
   strcat(of_path, disk);
110f85
   return of_path;
110f85
 }