Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1phOPE-0000qh-G4 for mharc-grub-devel@gnu.org; Wed, 29 Mar 2023 01:31:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phOP6-0000qA-BL for grub-devel@gnu.org; Wed, 29 Mar 2023 01:31:24 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phOP4-0002Vi-1K for grub-devel@gnu.org; Wed, 29 Mar 2023 01:31:24 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32T5AFxE014762 for ; Wed, 29 Mar 2023 05:31:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=L3Cd7dJf8r+RH1jWMINS7bBkDm0CrRykH55w/HDa0kg=; b=OvZOWscSjD/N6qmBeoOKlPxWAnXxnnk42260/gEu3KmeVwa+HQLOPSRJAEQBywC4TAyw TRLfeTquVin0WKozl3cAHUQDirCtUc6IUUIUGUWSkNsiaOJQ+AVsoEB/hEU6n5ccxQDf mHvG0adw164DHIMz8lITfiiO3yEp3fWT8UH6uY+Lm83NFJEAybCUsEgI99E3FJ0WGeh0 MapYQsEYs+hpO9HN/wZo6BSjOgOW42dghtsTgRmVnais34voNicwLyrNifHqc5hn8IX2 4Mxbm/ZjmVwNH01AGReVUd0MeWa+5hRyOhgjg2wo2w8Xkb2CFM3wt5xcRgyWH47f2ZtX CA== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pme3f9g4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 29 Mar 2023 05:31:16 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32SNaiZw029355 for ; Wed, 29 Mar 2023 05:30:57 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3phr7fmpd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 29 Mar 2023 05:30:57 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32T5UsXh23397106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Mar 2023 05:30:55 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D66892004F; Wed, 29 Mar 2023 05:30:54 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3426A20040; Wed, 29 Mar 2023 05:30:51 +0000 (GMT) Received: from li-e1dea04c-3555-11b2-a85c-f57333552245.ibm.com.com (unknown [9.43.59.37]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 29 Mar 2023 05:30:50 +0000 (GMT) From: Mukesh Kumar Chaurasiya To: grub-devel@gnu.org Cc: meghanaprakash@in.ibm.com, avnish@linux.vnet.ibm.com, brking@linux.vnet.ibm.com, mamatha4@linux.vnet.ibm.com, mchauras@linux.vnet.ibm.com, Diego Domingos Subject: [PATCH V2] ieee1275/ofdisk: retry on open and read failure Date: Wed, 29 Mar 2023 11:00:13 +0530 Message-Id: <20230329053012.111973-1-mchauras@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230328083456.rxspg42vvmdfp6lh@lore> References: <20230328083456.rxspg42vvmdfp6lh@lore> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LJz_VgwNIWKSKrfznDLD9BZqgmsnXI8M X-Proofpoint-ORIG-GUID: LJz_VgwNIWKSKrfznDLD9BZqgmsnXI8M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-24_11,2023-03-28_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 mlxscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxlogscore=792 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303290043 Received-SPF: none client-ip=148.163.156.1; envelope-from=mchauras@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Mar 2023 05:31:25 -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 DEFAULT_RETRY_TIMEOUT, which is 15000ms or 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. Signed-off-by: Diego Domingos Signed-off-by: Mukesh Kumar Chaurasiya --- grub-core/disk/ieee1275/ofdisk.c | 65 +++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index c6cba0c8a..f4183a531 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -24,6 +24,9 @@ #include #include #include +#include + +#define RETRY_DEFAULT_TIMEOUT 15000 static 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; @@ -525,6 +528,41 @@ grub_ofdisk_open (const char *name, grub_disk_t disk) return 0; } +static grub_uint64_t +grub_ofdisk_disk_timeout(void) +{ + if(grub_env_get("ofdisk_retry_timeout") != NULL) + { + grub_uint64_t retry = grub_strtoul(grub_env_get("ofdisk_retry_timeout"), 0, 10); + if(retry) + return retry; + } + + return RETRY_DEFAULT_TIMEOUT; +} + +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(); + + retry: + err = grub_ofdisk_open_real (name, disk); + + if (err == GRUB_ERR_UNKNOWN_DEVICE) + { + if (grub_get_time_ms () < timeout) + { + grub_dprintf ("ofdisk","Failed to open disk %s. Retrying...\n", name); + grub_errno = GRUB_ERR_NONE; + goto retry; + } + } + + return err; +} + static void grub_ofdisk_close (grub_disk_t disk) { @@ -568,7 +606,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; @@ -587,6 +625,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) +{ + grub_err_t err; + grub_uint64_t timeout = grub_get_time_ms () + grub_ofdisk_disk_timeout(); + + retry: + err = grub_ofdisk_read_real (disk, sector, size, buf); + + if (err == GRUB_ERR_READ_ERROR) + { + if (grub_get_time_ms () < timeout) + { + grub_dprintf ("ofdisk","Failed to read disk %s. Retrying...\n", (char*)disk->data); + grub_errno = GRUB_ERR_NONE; + goto retry; + } + } + + return err; +} + static grub_err_t grub_ofdisk_write (grub_disk_t disk, grub_disk_addr_t sector, grub_size_t size, const char *buf) -- 2.31.1