nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0485-ieee1275-ofdisk-retry-on-open-failure.patch

f20682
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f20682
From: Diego Domingos <diegodo@br.ibm.com>
f20682
Date: Wed, 10 Mar 2021 14:17:52 -0500
f20682
Subject: [PATCH] ieee1275/ofdisk: retry on open failure
f20682
f20682
This patch aims to make grub more robust when booting from SAN/Multipath disks.
f20682
f20682
If a path is failing intermittently so grub will retry the OPEN and READ the
f20682
disk (grub_ieee1275_open and grub_ieee1275_read) until the total amount of times
f20682
specified in MAX_RETRIES.
f20682
f20682
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
f20682
---
f20682
 grub-core/disk/ieee1275/ofdisk.c | 25 ++++++++++++++++++++-----
f20682
 include/grub/ieee1275/ofdisk.h   |  8 ++++++++
f20682
 2 files changed, 28 insertions(+), 5 deletions(-)
f20682
f20682
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
b32e65
index f3a6ecd79..98325ca98 100644
f20682
--- a/grub-core/disk/ieee1275/ofdisk.c
f20682
+++ b/grub-core/disk/ieee1275/ofdisk.c
f20682
@@ -225,7 +225,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
f20682
       char *buf, *bufptr;
f20682
       unsigned i;
f20682
 
f20682
-      if (grub_ieee1275_open (alias->path, &ihandle))
f20682
+
f20682
+      RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle)
f20682
+      if (! ihandle)
f20682
 	return;
f20682
 
f20682
       /* This method doesn't need memory allocation for the table. Open
f20682
@@ -305,7 +307,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
f20682
           return;
f20682
         }
f20682
 
f20682
-      if (grub_ieee1275_open (alias->path, &ihandle))
f20682
+      RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle);
f20682
+
f20682
+      if (! ihandle)
f20682
         {
f20682
           grub_free (buf);
f20682
           grub_free (table);
f20682
@@ -495,7 +499,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
f20682
     last_ihandle = 0;
f20682
     last_devpath = NULL;
f20682
 
f20682
-    grub_ieee1275_open (op->open_path, &last_ihandle);
f20682
+    RETRY_IEEE1275_OFDISK_OPEN(op->open_path, &last_ihandle);
f20682
     if (! last_ihandle)
f20682
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
f20682
     last_devpath = op->open_path;
f20682
@@ -571,7 +575,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
f20682
       last_ihandle = 0;
f20682
       last_devpath = NULL;
f20682
 
f20682
-      grub_ieee1275_open (disk->data, &last_ihandle);
f20682
+      RETRY_IEEE1275_OFDISK_OPEN(disk->data, &last_ihandle);
f20682
       if (! last_ihandle)
f20682
 	return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
f20682
       last_devpath = disk->data;      
f20682
@@ -598,12 +602,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
f20682
     return err;
f20682
   grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
f20682
 		      &actual);
f20682
-  if (actual != (grub_ssize_t) (size  << disk->log_sector_size))
f20682
+  int i = 0;
f20682
+  while(actual != (grub_ssize_t) (size  << disk->log_sector_size)){
f20682
+    if (i>MAX_RETRIES){
f20682
     return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx "
f20682
 					       "from `%s'"),
f20682
 		       (unsigned long long) sector,
f20682
 		       disk->name);
f20682
+    }
f20682
+    last_devpath = NULL;
f20682
+    err = grub_ofdisk_prepare (disk, sector);
f20682
+    if (err)
f20682
+      return err;
f20682
 
f20682
+    grub_ieee1275_read (last_ihandle, buf, size  << disk->log_sector_size,
f20682
+                      &actual);
f20682
+    i++;
f20682
+  }
f20682
   return 0;
f20682
 }
f20682
 
f20682
diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h
b32e65
index 2f69e3f19..7d2d54093 100644
f20682
--- a/include/grub/ieee1275/ofdisk.h
f20682
+++ b/include/grub/ieee1275/ofdisk.h
f20682
@@ -22,4 +22,12 @@
f20682
 extern void grub_ofdisk_init (void);
f20682
 extern void grub_ofdisk_fini (void);
f20682
 
f20682
+#define MAX_RETRIES 20
f20682
+
f20682
+
f20682
+#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) unsigned retry_i=0;for(retry_i=0; retry_i < MAX_RETRIES; retry_i++){ \
f20682
+						if(!grub_ieee1275_open(device, last_ihandle)) \
f20682
+						break; \
f20682
+						grub_dprintf("ofdisk","Opening disk %s failed. Retrying...\n",device); }
f20682
+
f20682
 #endif /* ! GRUB_INIT_HEADER */