[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
From: |
Petr Vorel |
Subject: |
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup |
Date: |
Tue, 13 Jul 2021 21:10:39 +0200 |
Hi all,
> On 7/13/21 1:48 PM, Daniel Kiper wrote:
> > On Thu, Jul 08, 2021 at 05:55:58PM +0200, Petr Vorel wrote:
> >> From: Jeff Mahoney <jeffm@suse.com>
> >> 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>
> >> [ pvorel: include grub/osdep/major.h ]
> >> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> >> ---
> >> grub-core/osdep/linux/hostdisk.c | 8 ++++++++
> >> 1 file changed, 8 insertions(+)
> >> diff --git a/grub-core/osdep/linux/hostdisk.c
> >> b/grub-core/osdep/linux/hostdisk.c
> >> index da62f924e..43dc4b0ba 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>
> >> @@ -105,6 +106,13 @@ sysfs_partition_path (const char *dev, const char
> >> *entry)
> >> char *buf = NULL;
> >> size_t len = 0;
> >> char *path = NULL;
> >> + struct stat st;
> >> + int ret;
> >> +
> >> + ret = stat(dev, &st);
> > Missing space between "stat" and "(".
> >> + if (ret == 0 && S_ISBLK(st.st_mode))
> > Same for S_ISBLK...
> >> + return xasprintf ("/sys/dev/block/%u:%u/%s",
> >> + major (st.st_rdev), minor (st.st_rdev), entry);
> >> argv[0] = "udevadm";
> >> argv[1] = "info";
> > Do we really need udevadm fallback mechanism? If something went wrong
> > here for us I do not expect it will work for udevadm either.
> I suspect not. 'udevadm info --query path --name <dev>' does
> essentially the same thing but with many more steps and the cost
> starting an external program for every block device. I left it in with
> the assumption that it was probably there for a reason and perhaps
> udevadm on early udev systems did something more special than just doing
> stat + sysfs path building. I didn't spend any time on validating that
> assumption.
As it'd be wort to remove udevadm fallback, I'll stop being lazy and setup VM to
test.
Kind regards,
Petr
> -Jeff
[PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/08
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Daniel Kiper, 2021/07/13
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/13
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/14
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Daniel Kiper, 2021/07/14
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/14
- Re: [PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/14