File grub2-use-stat-instead-of-udevadm-for-partition-lookup.patch of Package grub2.16104

From: Jeff Mahoney <jeffm@suse.com>
Subject: grub2: use stat instead of udevadm for partition lookup
References: bnc#883635

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 grub2-mkconfig from 10s to 2s on
my system.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 grub-core/osdep/linux/hostdisk.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

--- a/grub-core/osdep/linux/hostdisk.c
+++ b/grub-core/osdep/linux/hostdisk.c
@@ -105,6 +106,13 @@ sysfs_partition_path (const char *dev, c
   char *buf = NULL;
   size_t len = 0;
   char *path = NULL;
+  struct stat st;
+  int ret;
+
+  ret = stat(dev, &st);
+  if (ret == 0 && S_ISBLK(st.st_mode))
+    return xasprintf ("/sys/dev/block/%u:%u/%s",
+		      major (st.st_rdev), minor (st.st_rdev), entry);
 
   argv[0] = "udevadm";
   argv[1] = "info";
openSUSE Build Service is sponsored by