SHA256
1
0
forked from pool/grub2
grub2/0002-osdep-linux-hostdisk-Use-stat-instead-of-udevadm-for.patch
Michael Chang 8704ee74b5 Accepting request 910108 from home:pevik:branches:Base:System
- Replace grub2-use-stat-instead-of-udevadm-for-partition-lookup.patch and
  fix-grub2-use-stat-instead-of-udevadm-for-partition-lookup-with-new-glibc.patch
  with upstream backport:
  0001-osdep-Introduce-include-grub-osdep-major.h-and-use-i.patch and
  0002-osdep-linux-hostdisk-Use-stat-instead-of-udevadm-for.patch.

OBS-URL: https://build.opensuse.org/request/show/910108
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=388
2021-08-05 02:21:26 +00:00

99 lines
2.7 KiB
Diff

From 1ea4e5ef09c06552402bf676ce262a661372f08d Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Thu, 15 Jul 2021 17:35:28 +0200
Subject: [PATCH 2/2] osdep/linux/hostdisk: Use stat() instead of udevadm for
partition lookup
The sysfs_partition_path() calls udevadm to resolve the sysfs path for
a block device. That can be accomplished by stating the device node
and using the major/minor to follow the symlinks in /sys/dev/block/.
This cuts the execution time of grub-mkconfig to somewhere near 55% on
system without LVM (which uses libdevmapper instead sysfs_partition_path()).
Remove udevadm call as it does not help us more than calling stat() directly.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
[ upstream status: 1ea4e5ef0 ("osdep/linux/hostdisk: Use stat() instead of udevadm for partition lookup")
---
grub-core/osdep/linux/hostdisk.c | 52 ++++----------------------------
1 file changed, 6 insertions(+), 46 deletions(-)
diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
index da62f924e..d3326d095 100644
--- a/grub-core/osdep/linux/hostdisk.c
+++ b/grub-core/osdep/linux/hostdisk.c
@@ -31,6 +31,7 @@
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/list.h>
+#include <grub/osdep/major.h>
#include <stdio.h>
#include <stdlib.h>
@@ -98,54 +99,13 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
static char *
sysfs_partition_path (const char *dev, const char *entry)
{
- const char *argv[7];
- int fd;
- pid_t pid;
- FILE *udevadm;
- char *buf = NULL;
- size_t len = 0;
- char *path = NULL;
-
- argv[0] = "udevadm";
- argv[1] = "info";
- argv[2] = "--query";
- argv[3] = "path";
- argv[4] = "--name";
- argv[5] = dev;
- argv[6] = NULL;
-
- pid = grub_util_exec_pipe (argv, &fd);
-
- if (!pid)
- return NULL;
-
- /* Parent. Read udevadm's output. */
- udevadm = fdopen (fd, "r");
- if (!udevadm)
- {
- grub_util_warn (_("Unable to open stream from %s: %s"),
- "udevadm", strerror (errno));
- close (fd);
- goto out;
- }
-
- if (getline (&buf, &len, udevadm) > 0)
- {
- char *newline;
-
- newline = strchr (buf, '\n');
- if (newline)
- *newline = '\0';
- path = xasprintf ("/sys%s/%s", buf, entry);
- }
+ struct stat st;
-out:
- if (udevadm)
- fclose (udevadm);
- waitpid (pid, NULL, 0);
- free (buf);
+ if (stat (dev, &st) == 0 && S_ISBLK (st.st_mode))
+ return xasprintf ("/sys/dev/block/%u:%u/%s",
+ major (st.st_rdev), minor (st.st_rdev), entry);
- return path;
+ return NULL;
}
static int
--
2.32.0