Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lf1Gz-0005Vy-6J for mharc-grub-devel@gnu.org; Fri, 07 May 2021 10:16:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1Gx-0005RQ-8U for grub-devel@gnu.org; Fri, 07 May 2021 10:16:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:4308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1Gu-0007dt-MU for grub-devel@gnu.org; Fri, 07 May 2021 10:16:06 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 147E4OYQ151237 for ; Fri, 7 May 2021 10:16:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=27G35M8P9Gmt+iFeEOyLXknj2g8eazfZNUbhn37WTWE=; b=YsuXHdlV7MecTwETIo74OFWSEuOsZwXNEQZ58wP0tw8sDiLeau2ghvVbnaURtWlamTUF b2nJ45t5VFb0DqDL19dtUeokgtVYjxuMyWI9DnTKPc6e8vJjm2ElJhqbkHw5CAPa1cf1 YqHJXHR1t681R0SVUFyLUXcfCT9Rfr69/EOulEioAG4NHYxWrZY25kC2/hm2mBn3DC3E CjAzPWXJf/uFgxIJ/BnPgmfkUEbYglCGvbQouXGyRpeFhfIcqjTVKsjmkzJnp5tVEeWE iHUDtAOJUy+NzPBFuViaSMb508MYDSVumwoJ0cA2SAUo+k/D2IDOYrU2sIsQ8+xODZlC jQ== Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 38d5jxuf0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 07 May 2021 10:16:01 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 147E9fC8002729 for ; Fri, 7 May 2021 14:16:01 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma03wdc.us.ibm.com with ESMTP id 38csqe4e5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 07 May 2021 14:16:01 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 147EG0Kx34931012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 7 May 2021 14:16:00 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CF318AE06B for ; Fri, 7 May 2021 14:16:00 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46ED9AE05F for ; Fri, 7 May 2021 14:16:00 +0000 (GMT) Received: from localhost.localdomain (unknown [9.65.203.196]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP for ; Fri, 7 May 2021 14:15:59 +0000 (GMT) From: Diego Domingos To: grub-devel@gnu.org Subject: [PATCH] ieee1275/ofdisk: retry on open and read failure Date: Fri, 7 May 2021 11:15:43 -0300 Message-Id: <20210507141543.259136-1-diegodo@linux.vnet.ibm.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: t7HUsBmVtjEb4o36HT88w2M1uST6kwxm X-Proofpoint-ORIG-GUID: t7HUsBmVtjEb4o36HT88w2M1uST6kwxm X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-07_06:2021-05-06, 2021-05-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=711 lowpriorityscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 impostorscore=0 phishscore=0 clxscore=1011 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105070093 Received-SPF: none client-ip=148.163.158.5; envelope-from=diegodo@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2021 14:16:07 -0000 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 after it fails. We use MAX_RETRIES to specify the amount of times it will try to access the disk before it definitely fails. --- grub-core/disk/ieee1275/ofdisk.c | 27 +++++++++++++++++++++------ include/grub/ieee1275/ofdisk.h | 8 ++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index d887d4b..777ae63 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -225,7 +225,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) char *buf, *bufptr; unsigned i; - if (grub_ieee1275_open (alias->path, &ihandle)) + + RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle) + if (! ihandle) return; /* This method doesn't need memory allocation for the table. Open @@ -305,7 +307,9 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) return; } - if (grub_ieee1275_open (alias->path, &ihandle)) + RETRY_IEEE1275_OFDISK_OPEN(alias->path, &ihandle) + + if (! ihandle) { grub_free (buf); grub_free (table); @@ -555,7 +559,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector) last_ihandle = 0; last_devpath = NULL; - grub_ieee1275_open (disk->data, &last_ihandle); + RETRY_IEEE1275_OFDISK_OPEN(disk->data, &last_ihandle) if (! last_ihandle) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); last_devpath = disk->data; @@ -582,12 +586,23 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector, return err; grub_ieee1275_read (last_ihandle, buf, size << disk->log_sector_size, &actual); - if (actual != (grub_ssize_t) (size << disk->log_sector_size)) + int i = 0; + while(actual != (grub_ssize_t) (size << disk->log_sector_size)){ + if (i>10){ return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading sector 0x%llx " "from `%s'"), (unsigned long long) sector, disk->name); - + } + grub_dprintf("ofdisk","Read failed. Retrying...\n"); + last_devpath = NULL; + err = grub_ofdisk_prepare (disk, sector); + if (err) + return err; + grub_ieee1275_read (last_ihandle, buf, size << disk->log_sector_size, + &actual); + i++; + } return 0; } @@ -704,7 +719,7 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size, last_ihandle = 0; last_devpath = NULL; - grub_ieee1275_open (device, &last_ihandle); + RETRY_IEEE1275_OFDISK_OPEN (device, &last_ihandle) if (! last_ihandle) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h index 2f69e3f..124e297 100644 --- a/include/grub/ieee1275/ofdisk.h +++ b/include/grub/ieee1275/ofdisk.h @@ -22,4 +22,12 @@ extern void grub_ofdisk_init (void); extern void grub_ofdisk_fini (void); +#define MAX_RETRIES 20 + + +#define RETRY_IEEE1275_OFDISK_OPEN(device, last_ihandle) unsigned retry_i=0;for(retry_i=0; retry_i < MAX_RETRIES; retry_i++){ \ + if(!grub_ieee1275_open(device, last_ihandle)) \ + break; \ + grub_dprintf("ofdisk","Opening disk %s failed. Retrying...\n",device); } + #endif /* ! GRUB_INIT_HEADER */ -- 2.27.0