Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kgBO0-0007EC-0h for mharc-grub-devel@gnu.org; Fri, 20 Nov 2020 13:43:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBNy-0007Br-39 for grub-devel@gnu.org; Fri, 20 Nov 2020 13:43:54 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:62912 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgBNw-0003t4-AD for grub-devel@gnu.org; Fri, 20 Nov 2020 13:43:53 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AKIZBqG144154 for ; Fri, 20 Nov 2020 13:43:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=x+gJ0G8o5rhKY7/3XEEwvAgU8Y3TNV7WE8SOjoNXytM=; b=A0LKEjx0cx9VCy1g4214Zj/7mEpNyn5HxfCuzQ3dkZ2LHjNkYuMYXwrQSX4bKFF9VMNZ ZXPGFcTIBS0oVt/f5IWdS29md82ZuAZc+aTUD7vujKG8IfLIFXX6cZhjNRbHM4fImkMH 5wFlCWjQ0PsRrAhbpo8cnOINKjiryNMNm/3levYTNFLmFNP+RNe0M5yZZNCsCOYr3QnB KH4rHDx/HN/SRXcOu6uAXd0VnYZy3RXXACVL6oBVuO4Q8RZOLHvCco2GDE3X1kLyO9nK +457HJAkuU6QKv7ZK8s5YRvASphv6n4HJRGNuCya4ptdxV9tfSwZLmzqEo3PHCz8bV8B 8g== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 34xgsndk3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 20 Nov 2020 13:43:49 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AKIQoTX015815 for ; Fri, 20 Nov 2020 18:43:49 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma01wdc.us.ibm.com with ESMTP id 34uyn1yfg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 20 Nov 2020 18:43:49 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AKIhmRx13501024 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Nov 2020 18:43:48 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8DCD7112062 for ; Fri, 20 Nov 2020 18:43:48 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EAEA1112061 for ; Fri, 20 Nov 2020 18:43:47 +0000 (GMT) Received: from unknown.ibmuc.com (unknown [9.160.51.162]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 18:43:47 +0000 (GMT) From: Diego Domingos To: grub-devel@gnu.org Subject: [PATCH 2/2] ieee1275/powerpc: enables device mapper discovery Date: Fri, 20 Nov 2020 15:43:44 -0300 Message-Id: <20201120184344.9281-3-diegodo@linux.vnet.ibm.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201120184344.9281-1-diegodo@linux.vnet.ibm.com> References: <20201120184344.9281-1-diegodo@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-20_12:2020-11-20, 2020-11-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 mlxlogscore=929 phishscore=0 mlxscore=0 clxscore=1015 suspectscore=3 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011200124 Received-SPF: none client-ip=148.163.158.5; envelope-from=diegodo@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, RCVD_IN_DNSWL_NONE=-0.0001, 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, 20 Nov 2020 18:43:54 -0000 From: Diego Domingos this patch enables the device mapper discovery on ofpath.c. Currently, when we are dealing with a device like /dev/dm-* the ofpath returns null since there is no function implemented to handle this case. This patch implements a function that will look into /sys/block/dm-* devices and search recursively inside slaves directory to find the root disk. --- grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c index 0f5d54e9f..cc849d9c9 100644 --- a/grub-core/osdep/linux/ofpath.c +++ b/grub-core/osdep/linux/ofpath.c @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef __sparc__ typedef enum @@ -755,13 +756,74 @@ strip_trailing_digits (const char *p) return new; } +static char * +get_slave_from_dm(const char * device){ + char *curr_device, *tmp; + char *directory; + char *ret = NULL; + + directory = grub_strdup (device); + tmp = get_basename(directory); + curr_device = grub_strdup (tmp); + *tmp = '\0'; + + /* Recursively check for slaves devices so we can find the root device */ + while ((curr_device[0] == 'd') && (curr_device[1] == 'm') && (curr_device[2] == '-')){ + DIR *dp; + struct dirent *ep; + char* device_path; + + device_path = grub_xasprintf ("/sys/block/%s/slaves", curr_device); + dp = opendir(device_path); + free(device_path); + + if (dp != NULL) + { + ep = readdir (dp); + while (ep != NULL){ + + /* avoid some system directories */ + if (!strcmp(ep->d_name,".")) + goto next_dir; + if (!strcmp(ep->d_name,"..")) + goto next_dir; + + free (curr_device); + free (ret); + curr_device = grub_strdup (ep->d_name); + ret = grub_xasprintf ("%s%s", directory, curr_device); + break; + + next_dir: + ep = readdir (dp); + continue; + } + closedir (dp); + } + else + grub_util_warn (_("cannot open directory `%s'"), device_path); + } + + free (directory); + free (curr_device); + + return ret; +} + char * grub_util_devname_to_ofpath (const char *sys_devname) { - char *name_buf, *device, *devnode, *devicenode, *ofpath; + char *name_buf, *device, *devnode, *devicenode, *ofpath, *realname; name_buf = xrealpath (sys_devname); + realname = get_slave_from_dm (name_buf); + if (realname) + { + free (name_buf); + name_buf = realname; + } + device = get_basename (name_buf); devnode = strip_trailing_digits (name_buf); devicenode = strip_trailing_digits (device); -- 2.21.3