dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0367-util-ieee1275-ofpath.c-of_path_of_scsi-Fix-path-outp.patch

f96e0b
From a1de3862b9c2acd1afdcbd42f79b8b7694a0a794 Mon Sep 17 00:00:00 2001
f96e0b
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
Date: Sat, 27 Apr 2013 22:03:13 +0200
f96e0b
Subject: [PATCH 367/482] 	* util/ieee1275/ofpath.c (of_path_of_scsi):
f96e0b
 Fix path output for sas 	disks. 	(check_sas): Get sas_adress info.
f96e0b
f96e0b
---
f96e0b
 ChangeLog              |  6 ++++
f96e0b
 util/ieee1275/ofpath.c | 76 +++++++++++++++++++++++++++++++++++++++-----------
f96e0b
 2 files changed, 66 insertions(+), 16 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 317a367..83cdafc 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,9 @@
f96e0b
+2013-04-27  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
+
f96e0b
+	* util/ieee1275/ofpath.c (of_path_of_scsi): Fix path output for sas
f96e0b
+	disks.
f96e0b
+	(check_sas): Get sas_adress info.
f96e0b
+
f96e0b
 2013-04-27  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/disk/ahci.c (grub_ahci_pciinit): Fix handling of empty
f96e0b
diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c
f96e0b
index f0a34b5..5fde979 100644
f96e0b
--- a/util/ieee1275/ofpath.c
f96e0b
+++ b/util/ieee1275/ofpath.c
f96e0b
@@ -324,11 +324,11 @@ vendor_is_ATA(const char *path)
f96e0b
 }
f96e0b
 
f96e0b
 static void
f96e0b
-check_sas (char *sysfs_path, int *tgt)
f96e0b
+check_sas (char *sysfs_path, int *tgt, unsigned long int *sas_address)
f96e0b
 {
f96e0b
   char *ed = strstr (sysfs_path, "end_device");
f96e0b
   char *p, *q, *path;
f96e0b
-  char phy[16];
f96e0b
+  char phy[21];
f96e0b
   int fd;
f96e0b
   size_t path_size;
f96e0b
 
f96e0b
@@ -348,16 +348,25 @@ check_sas (char *sysfs_path, int *tgt)
f96e0b
 	       + sizeof ("%s/sas_device/%s/phy_identifier"));
f96e0b
   path = xmalloc (path_size);
f96e0b
   snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed);
f96e0b
-
f96e0b
   fd = open (path, O_RDONLY);
f96e0b
   if (fd < 0)
f96e0b
     grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
f96e0b
 
f96e0b
   memset (phy, 0, sizeof (phy));
f96e0b
-  read (fd, phy, sizeof (phy));
f96e0b
+  read (fd, phy, sizeof (phy) - 1);
f96e0b
+  close (fd);
f96e0b
 
f96e0b
   sscanf (phy, "%d", tgt);
f96e0b
 
f96e0b
+  snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed);
f96e0b
+  fd = open (path, O_RDONLY);
f96e0b
+  if (fd < 0)
f96e0b
+  grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
f96e0b
+
f96e0b
+  memset (phy, 0, sizeof (phy));
f96e0b
+  read (fd, phy, sizeof (phy) - 1);
f96e0b
+  sscanf (phy, "%lx", sas_address);
f96e0b
+
f96e0b
   free (path);
f96e0b
   free (p);
f96e0b
   close (fd);
f96e0b
@@ -370,13 +379,14 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
f96e0b
 {
f96e0b
   const char *p, *digit_string, *disk_name;
f96e0b
   int host, bus, tgt, lun;
f96e0b
+  unsigned long int sas_address;
f96e0b
   char *sysfs_path, disk[MAX_DISK_CAT - sizeof ("/fp@0,0")];
f96e0b
   char *of_path;
f96e0b
 
f96e0b
   sysfs_path = block_device_get_sysfs_path_and_link(devicenode);
f96e0b
   p = get_basename (sysfs_path);
f96e0b
   sscanf(p, "%d:%d:%d:%d", &host, &bus, &tgt, &lun;;
f96e0b
-  check_sas (sysfs_path, &tgt);
f96e0b
+  check_sas (sysfs_path, &tgt, &sas_address);
f96e0b
 
f96e0b
   if (vendor_is_ATA(sysfs_path))
f96e0b
     {
f96e0b
@@ -417,18 +427,52 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
f96e0b
     }
f96e0b
   else
f96e0b
     {
f96e0b
-      if (*digit_string == '\0')
f96e0b
-	{
f96e0b
-	  snprintf(disk, sizeof (disk), "/%s@%x,%d", disk_name, tgt, lun);
f96e0b
-	}
f96e0b
+      if (lun == 0)
f96e0b
+        {
f96e0b
+          int sas_id = 0;
f96e0b
+          sas_id = bus << 16 | tgt << 8 | lun;
f96e0b
+
f96e0b
+          if (*digit_string == '\0')
f96e0b
+            {
f96e0b
+              snprintf(disk, sizeof (disk), "/sas/%s@%x", disk_name, sas_id);
f96e0b
+            }
f96e0b
+          else
f96e0b
+            {
f96e0b
+              int part;
f96e0b
+
f96e0b
+              sscanf(digit_string, "%d", &part);
f96e0b
+              snprintf(disk, sizeof (disk),
f96e0b
+                       "/sas/%s@%x:%c", disk_name, sas_id, 'a' + (part - 1));
f96e0b
+            }
f96e0b
+        }
f96e0b
       else
f96e0b
-	{
f96e0b
-	  int part;
f96e0b
-
f96e0b
-	  sscanf(digit_string, "%d", &part);
f96e0b
-	  snprintf(disk, sizeof (disk),
f96e0b
-		   "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1));
f96e0b
-	}
f96e0b
+        {
f96e0b
+          char *lunstr;
f96e0b
+          int lunpart[4];
f96e0b
+
f96e0b
+          lunstr = xmalloc (20);
f96e0b
+
f96e0b
+          lunpart[0] = (lun >> 8) & 0xff;
f96e0b
+          lunpart[1] = lun & 0xff;
f96e0b
+          lunpart[2] = (lun >> 24) & 0xff;
f96e0b
+          lunpart[3] = (lun >> 16) & 0xff;
f96e0b
+
f96e0b
+          sprintf(lunstr, "%02x%02x%02x%02x00000000", lunpart[0], lunpart[1], lunpart[2], lunpart[3]);
f96e0b
+          long int longlun = atol(lunstr);
f96e0b
+
f96e0b
+          if (*digit_string == '\0')
f96e0b
+            {
f96e0b
+              snprintf(disk, sizeof (disk), "/sas/%s@%lx,%lu", disk_name, sas_address, longlun);
f96e0b
+            }
f96e0b
+          else
f96e0b
+            {
f96e0b
+              int part;
f96e0b
+
f96e0b
+              sscanf(digit_string, "%d", &part);
f96e0b
+              snprintf(disk, sizeof (disk),
f96e0b
+                       "/sas/%s@%lx,%lu:%c", disk_name, sas_address, longlun, 'a' + (part - 1));
f96e0b
+            }
f96e0b
+        }
f96e0b
     }
f96e0b
   strcat(of_path, disk);
f96e0b
   return of_path;
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b