nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

dbe756
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
dbe756
From: Diego Domingos <diegodo@br.ibm.com>
dbe756
Date: Mon, 14 Dec 2020 17:45:28 +0100
dbe756
Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for
dbe756
 ofpathname
dbe756
dbe756
grub-ofpathname doesn't work with fibre channel because there is no
dbe756
function currently implemented for it.
dbe756
This patch enables it by prividing a function that looks for the port
dbe756
name, building the entire path for OF devices.
dbe756
dbe756
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
dbe756
---
dbe756
 grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++++++++++
dbe756
 1 file changed, 49 insertions(+)
dbe756
dbe756
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
09e3cc
index a6153d359..0f5d54e9f 100644
dbe756
--- a/grub-core/osdep/linux/ofpath.c
dbe756
+++ b/grub-core/osdep/linux/ofpath.c
dbe756
@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
dbe756
   return ret;
dbe756
 }
dbe756
 
dbe756
+
dbe756
+static void
dbe756
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
dbe756
+{
dbe756
+  char *bname, *basepath, *p;
dbe756
+  int fd;
dbe756
+
dbe756
+  bname = xmalloc(sizeof(char)*150);
dbe756
+  basepath = xmalloc(strlen(path));
dbe756
+
dbe756
+  /* Generate the path to get port name information from the drive */
dbe756
+  strncpy(basepath,path,subpath-path);
dbe756
+  basepath[subpath-path-1] = '\0';
dbe756
+  p = get_basename(basepath);
dbe756
+  snprintf(bname,sizeof(char)*150,"%s/fc_transport/%s/port_name",basepath,p);
dbe756
+
dbe756
+  /* Read the information from the port name */
dbe756
+  fd = open (bname, O_RDONLY);
dbe756
+  if (fd < 0)
dbe756
+    grub_util_error (_("cannot open `%s': %s"), bname, strerror (errno));
dbe756
+
dbe756
+  if (read(fd,port_name,sizeof(char)*19) < 0)
dbe756
+    grub_util_error (_("cannot read `%s': %s"), bname, strerror (errno));
dbe756
+
dbe756
+  sscanf(port_name,"0x%s",port_name);
dbe756
+  
dbe756
+  close(fd);
dbe756
+
dbe756
+  free(bname);
dbe756
+  free(basepath);
dbe756
+}
dbe756
+
dbe756
 #ifdef __sparc__
dbe756
 static char *
dbe756
 of_path_of_nvme(const char *sys_devname __attribute__((unused)),
dbe756
@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
dbe756
   digit_string = trailing_digits (device);
dbe756
   if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
dbe756
     {
dbe756
+      if(strstr(of_path,"vfc-client"))
dbe756
+      {
dbe756
+	char * port_name = xmalloc(sizeof(char)*17);
dbe756
+	of_fc_port_name(sysfs_path, p, port_name);
dbe756
+	
dbe756
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
dbe756
+	free(port_name);
dbe756
+      }
dbe756
+      else
dbe756
+      {
dbe756
       unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
dbe756
       if (*digit_string == '\0')
dbe756
 	{
dbe756
@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
dbe756
 	  snprintf(disk, sizeof (disk),
dbe756
 		   "/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
dbe756
 	}
dbe756
+	}
dbe756
+    } else if (strstr(of_path,"fibre-channel")||(strstr(of_path,"vfc-client"))){
dbe756
+	char * port_name = xmalloc(sizeof(char)*17);
dbe756
+	of_fc_port_name(sysfs_path, p, port_name);
dbe756
+	
dbe756
+	snprintf(disk,sizeof(disk),"/%s@%s", disk_name, port_name);
dbe756
+	free(port_name);
dbe756
     }
dbe756
   else
dbe756
     {