All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] getroot: Skip mount points in grub_find_device
@ 2025-09-16  6:38 Michael Chang via Grub-devel
  2025-09-16 12:02 ` Neal Gompa
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Chang via Grub-devel @ 2025-09-16  6:38 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Michael Chang

The grub_find_device function scans a starting directory, typically
/dev, for device files with matching major and minor numbers. During
this process, it recursively descends into subdirectories.

However, this can significantly slow down the scan if a subdirectory is
a mount point not related to devtmpfs, especially if it contains a large
number of files.

This patch modifies grub_find_device() to skip subdirectories that are
mount points. A mount point is detected by comparing the st_dev of the
subdirectory against that of the parent or starting directory. While
this method does not catch all types of mounts, for eg bind mounts, it
is a practical solution that avoids the need to parse /proc/self/mounts.

Signed-off-by: Michael Chang <mchang@suse.com>
---
 grub-core/osdep/unix/getroot.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroot.c
index c7aa202ab..c3fc28ca8 100644
--- a/grub-core/osdep/unix/getroot.c
+++ b/grub-core/osdep/unix/getroot.c
@@ -353,6 +353,7 @@ grub_find_device (const char *dir, dev_t dev)
   DIR *dp;
   struct saved_cwd saved_cwd;
   struct dirent *ent;
+  struct stat st_dir;
 
   if (! dir)
     dir = "/dev";
@@ -361,6 +362,12 @@ grub_find_device (const char *dir, dev_t dev)
   if (! dp)
     return 0;
 
+  if (stat (dir, &st_dir) < 0)
+    {
+      closedir (dp);
+      return 0;
+    }
+
   if (save_cwd (&saved_cwd) < 0)
     {
       grub_util_error ("%s", _("cannot save the original directory"));
@@ -410,6 +417,13 @@ grub_find_device (const char *dir, dev_t dev)
 	  /* Find it recursively.  */
 	  char *res;
 
+	  /* Skip mount point */
+	  if (st.st_dev != st_dir.st_dev)
+	    {
+	      grub_util_info ("skip mount point %s/%s", dir, ent->d_name);
+	      continue;
+	    }
+
 	  res = grub_find_device (ent->d_name, dev);
 
 	  if (res)
-- 
2.51.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] getroot: Skip mount points in grub_find_device
  2025-09-16  6:38 Michael Chang via Grub-devel
@ 2025-09-16 12:02 ` Neal Gompa
  0 siblings, 0 replies; 4+ messages in thread
From: Neal Gompa @ 2025-09-16 12:02 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Michael Chang

On Tue, Sep 16, 2025 at 2:39 AM Michael Chang via Grub-devel
<grub-devel@gnu.org> wrote:
>
> The grub_find_device function scans a starting directory, typically
> /dev, for device files with matching major and minor numbers. During
> this process, it recursively descends into subdirectories.
>
> However, this can significantly slow down the scan if a subdirectory is
> a mount point not related to devtmpfs, especially if it contains a large
> number of files.
>
> This patch modifies grub_find_device() to skip subdirectories that are
> mount points. A mount point is detected by comparing the st_dev of the
> subdirectory against that of the parent or starting directory. While
> this method does not catch all types of mounts, for eg bind mounts, it
> is a practical solution that avoids the need to parse /proc/self/mounts.
>
> Signed-off-by: Michael Chang <mchang@suse.com>
> ---
>  grub-core/osdep/unix/getroot.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>

This looks reasonable to me.

Reviewed-by: Neal Gompa <ngompa13@gmail.com>



-- 
真実はいつも一つ!/ Always, there's only one truth!

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] docs/grub.texi: Fix build warnings in libgcrypt and blsuki doc
       [not found] <mailman.5114.1758024225.1197.grub-devel@gnu.org>
@ 2025-09-16 16:38 ` Avnish Chouhan
  2025-09-16 17:27 ` [PATCH] getroot: Skip mount points in grub_find_device Avnish Chouhan
  1 sibling, 0 replies; 4+ messages in thread
From: Avnish Chouhan @ 2025-09-16 16:38 UTC (permalink / raw)
  To: sridharm
  Cc: grub-devel, daniel.kiper, phcoder, sudhakar, stefanb, nayna,
	ssrish

On 2025-09-16 17:33, grub-devel-request@gnu.org wrote:
> Message: 1
> Date: Mon, 15 Sep 2025 11:58:32 -0500
> From: Andrew Hamilton <adhamilt@gmail.com>
> To: The development of GNU GRUB <grub-devel@gnu.org>
> Cc: daniel.kiper@oracle.com, phcoder@gmail.com,
> 	sudhakar@linux.ibm.com,  stefanb@linux.ibm.com, nayna@linux.ibm.com,
> 	ssrish@linux.ibm.com
> Subject: Re: [PATCH] docs/grub.texi: Fix build warnings in libgcrypt
> 	and blsuki doc
> Message-ID:
> 	<CA+04=DaRWxJQ5bfs4knb2iCy1tmBvqTOUN8rUuWyzfWGQcY2EQ@mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
> 
> Looks good to me.
> 
> Reviewed-by: Andrew Hamilton <adhamilt@gmail.com>

Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] getroot: Skip mount points in grub_find_device
       [not found] <mailman.5114.1758024225.1197.grub-devel@gnu.org>
  2025-09-16 16:38 ` [PATCH] docs/grub.texi: Fix build warnings in libgcrypt and blsuki doc Avnish Chouhan
@ 2025-09-16 17:27 ` Avnish Chouhan
  1 sibling, 0 replies; 4+ messages in thread
From: Avnish Chouhan @ 2025-09-16 17:27 UTC (permalink / raw)
  To: mchang; +Cc: grub-devel, Daniel Kiper

On 2025-09-16 17:33, grub-devel-request@gnu.org wrote:
> Message: 3
> Date: Tue, 16 Sep 2025 14:38:05 +0800
> From: Michael Chang <mchang@suse.com>
> To: The development of GNU GRUB <grub-devel@gnu.org>
> Subject: [PATCH] getroot: Skip mount points in grub_find_device
> Message-ID: <20250916063805.181388-1-mchang@suse.com>
> 
> The grub_find_device function scans a starting directory, typically
> /dev, for device files with matching major and minor numbers. During
> this process, it recursively descends into subdirectories.
> 
> However, this can significantly slow down the scan if a subdirectory is
> a mount point not related to devtmpfs, especially if it contains a 
> large
> number of files.
> 
> This patch modifies grub_find_device() to skip subdirectories that are
> mount points. A mount point is detected by comparing the st_dev of the
> subdirectory against that of the parent or starting directory. While
> this method does not catch all types of mounts, for eg bind mounts, it
> is a practical solution that avoids the need to parse 
> /proc/self/mounts.
> 
> Signed-off-by: Michael Chang <mchang@suse.com>

Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-16 17:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.5114.1758024225.1197.grub-devel@gnu.org>
2025-09-16 16:38 ` [PATCH] docs/grub.texi: Fix build warnings in libgcrypt and blsuki doc Avnish Chouhan
2025-09-16 17:27 ` [PATCH] getroot: Skip mount points in grub_find_device Avnish Chouhan
2025-09-16  6:38 Michael Chang via Grub-devel
2025-09-16 12:02 ` Neal Gompa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.