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