ieee1275/ofdisk: retry on open and read failure
PATCH v3 1/1 ieee1275/ofdisk: retry on open and read failure
Sometimes, when booting from a very busy SAN, the access to the disk can fail and then grub will eventually drop to grub prompt. This scenario is more frequent when deploying many machines at the same time using the same SAN.
This patch aims to force the ofdisk module to retry the open or read function for network disks excluding after it fails. We use DEFAULT_RETRY_TIMEOUT, which is 15 seconds to specify the time it'll retry to access the disk before it definitely fails. The timeout can be changed by setting the environment variable ofdisk_retry_timeout. If the environment variable fails to read, grub will consider the default value of 15 seconds.
--- docs/grub.texi | 8 ++++ grub-core/disk/ieee1275/ofdisk.c | 80 +++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-)
docs/grub.texi +8 -0
@@ -3336,6 +3336,7 @@ These variables have special meaning to GRUB. * net_default_ip:: * net_default_mac:: * net_default_server:: +* ofdisk_retry_timeout:: * pager:: * prefix:: * pxe_blksize::
@@ -3758,6 +3759,13 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}). @xref{Network}. +@node ofdisk_retry_timeout +@subsection ofdisk_retry_timeout + +The time in seconds till which the grub will retry to open or read a disk in +case of failure to do so. This value defaults to 15 seconds. + + @node pager @subsection pager
grub-core/disk/ieee1275/ofdisk.c +78 -2
110 lines not on this page · raw message
Signature · 1 line
2.39.3
Quoted 2 lines · Mukesh Kumar Chaurasiya
Sometimes, when booting from a very busy SAN, the access to the disk can fail and then grub will eventually drop to grub prompt.
s/grub/GRUB/ and below please...
Quoted 67 lines
This scenario is more frequent when deploying many machines at the same time using the same SAN.
This patch aims to force the ofdisk module to retry the open or read function for network disks excluding after it fails. We useDEFAULT_RETRY_TIMEOUT, which is 15 seconds to specify the time it'll retry to access the disk before it definitely fails. The timeout can be changed by setting the environment variableofdisk_retry_timeout. If the environment variable fails to read, grub will consider the default value of 15 seconds.Signed-off-by Diego Domingos <[email protected]>Signed-off-by Mukesh Kumar Chaurasiya <[email protected]>--- docs/grub.texi | 8 ++++ grub-core/disk/ieee1275/ofdisk.c | 80 +++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-)docs/grub.texi +8
-0@@ -3336,6 +3336,7 @@ These variables have special meaning to GRUB. * net_default_ip:: * net_default_mac:: * net_default_server:: +* ofdisk_retry_timeout:: * pager:: * prefix:: * pxe_blksize::@@ -3758,6 +3759,13 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}). @xref{Network}. +@node ofdisk_retry_timeout +@subsection ofdisk_retry_timeout + +The time in seconds till which the grub will retry to open or read a disk in +case of failure to do so. This value defaults to 15 seconds. + + @node pager @subsection pagergrub-core/disk/ieee1275/ofdisk.c +4
-1@@ -24,6 +24,9 @@#include <grub/ieee1275/ofdisk.h> #include <grub/i18n.h> #include <grub/time.h> +#include <grub/env.h> + +#define RETRY_DEFAULT_TIMEOUT 15static char *last_devpath;static grub_ieee1275_ihandle_t last_ihandle;@@ -452,7 +455,7 @@ compute_dev_path (const char *name) }static grub_err_t -grub_ofdisk_open (const char *name,grub_disk_t disk) +grub_ofdisk_open_real (const char *name,grub_disk_t disk) {grub_ieee1275_phandle_t dev;char *devpath;
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 534
Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +4
-0@@ -525,6 +528,56 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)return 0 ; } +static grub_uint64_t +grub_ofdisk_disk_timeout (grub_disk_t disk) +{ +grub_uint64_t retry;
grub_uint64_t retry = RETRY_DEFAULT_TIMEOUT;
... and you can simplify the code below...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 537
Quoted 3 lines
grub-core/disk/ieee1275/ofdisk.c +3
-0+const char *timeout =grub_env_get ("ofdisk_retry_timeout" ); + + if (!(grub_strstr (disk->name, "fibre-channel@") ||
grub_strstr (disk->name, "fibre-channel@") == NULL && grub_strstr (disk->name, "vfc-client")) == NULL && grub_strstr (disk->name, "nvme-of") == NULL)
... and then you do not need "!" above... And its clearer what you mean...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 541
Quoted 4 lines
grub-core/disk/ieee1275/ofdisk.c +4
-0+ grub_strstr (disk->name, "vfc-client")) || + grub_strstr(disk->name, "nvme-of")) + { +/* Do not retry in case of non network drives */
s/non network/non-network/g
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 548
Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +7
-0+return 0 ; + } + +if (timeout !=NULL ) + { + retry =grub_strtoul (timeout,0 ,10 ); +if (grub_errno !=GRUB_ERR_NONE )
This change is not fully correct. Please take a look at the commit ac8a37dda (net/http: Allow use of non-standard TCP/IP ports). Even if it is reverted the code around grub_strtoul() is fully correct.
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 554
Quoted 6 lines
grub-core/disk/ieee1275/ofdisk.c +6
-0+ { + grub_errno =GRUB_ERR_NONE ; +return RETRY_DEFAULT_TIMEOUT ; + } +if (retry) +return retry;
If you initialize "retry" at the beginning of this function you can drop this.
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 556
Quoted 2 lines
grub-core/disk/ieee1275/ofdisk.c +2
-0+ } +return RETRY_DEFAULT_TIMEOUT ;
... and you can do "return retry;" here...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 564
Quoted 8 lines
grub-core/disk/ieee1275/ofdisk.c +8
-0+} + +static grub_err_t +grub_ofdisk_open (const char *name,grub_disk_t disk) +{ +grub_err_t err; +grub_uint64_t timeout =grub_get_time_ms () + (grub_ofdisk_disk_timeout (disk) *1000 ); +_Bool cont;
s/_Bool/bool/
... and please add empty line after variables definition.
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 568
Quoted 4 lines
grub-core/disk/ieee1275/ofdisk.c +4
-0+ do + { + err = grub_ofdisk_open_real (name, disk); + cont = grub_get_time_ms () < timeout;
cont = (grub_get_time_ms () < timeout) ? true : false;
Ehhh... Even you can do...
do {
if (grub_get_time_ms () >= timeout)
break;
...
} while (1);The cont variable is not needed then...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 569
Quoted 1 line
grub-core/disk/ieee1275/ofdisk.c +1
-0+if (err ==GRUB_ERR_UNKNOWN_DEVICE && cont)
... && cont == true...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 571
Quoted 2 lines
grub-core/disk/ieee1275/ofdisk.c +2
-0+ { +grub_dprintf ("ofdisk" ,"Failed to open disk %s. Retrying...\n" , name);
Missing space after first ","...
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 577
Quoted 6 lines
grub-core/disk/ieee1275/ofdisk.c +6
-0+ grub_errno =GRUB_ERR_NONE ; + } +else +break ; +grub_millisleep (1000 ); + }while (cont);
cont == true
Quoted 16 lines
grub-core/disk/ieee1275/ofdisk.c +4
-1+return err; +} +static void grub_ofdisk_close (grub_disk_t disk) {@@ -568,7 +621,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector) }static grub_err_t -grub_ofdisk_read (grub_disk_t disk,grub_disk_addr_t sector, +grub_ofdisk_read_real (grub_disk_t disk,grub_disk_addr_t sector,grub_size_t size,char *buf) {grub_err_t err;
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, · line 646
Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +4
-0@@ -587,6 +640,29 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,return 0 ; } +static grub_err_t +grub_ofdisk_read (grub_disk_t disk,grub_disk_addr_t sector, +grub_size_t size,char *buf) +{
Most of the grub_ofdisk_open() comments apply to the grub_ofdisk_read().
Quoted 8 lines
grub-core/disk/ieee1275/ofdisk.c +8
-0+grub_err_t err; +grub_uint64_t timeout =grub_get_time_ms () + (grub_ofdisk_disk_timeout (disk) *1000 ); +_Bool cont; + do + { + err = grub_ofdisk_read_real (disk, sector, size, buf); + cont = grub_get_time_ms () < timeout; + if (err == GRUB_ERR_UNKNOWN_DEVICE && cont)
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, · line 664
Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10
-0+ { +grub_dprintf ("ofdisk" ,"Failed to read disk %s. Retrying...\n" , (char *)disk->data); + grub_errno =GRUB_ERR_NONE ; + } + else + break; +grub_millisleep (1000 ); + }while (cont); +return err; +}
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
grub-core/disk/ieee1275/ofdisk.c grub_ofdisk_open (const char *name, grub_disk_t disk) · line 576
Quoted 11 lines
grub-core/disk/ieee1275/ofdisk.c +11
-0+ { + err =grub_ofdisk_open_real (name, disk); + cont =grub_get_time_ms () < timeout; +if (err ==GRUB_ERR_UNKNOWN_DEVICE && cont) + { +grub_dprintf ("ofdisk" ,"Failed to open disk %s. Retrying...\n" , name); + grub_errno =GRUB_ERR_NONE ; + } +else +break ; +grub_millisleep (1000 );
Can you make this exponentially increasing and add a random number. Something like:
(32 << try) * (32 + random_between(-16, +16))
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel