nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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