nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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