[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: |
Michael Chang |
Subject: |
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup |
Date: |
Wed, 14 Jul 2021 12:16:02 +0800 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Tue, Jul 13, 2021 at 11:25:49AM +0200, Paul Menzel wrote:
> Dear Petr, dear Jeff,
>
>
> Am 08.07.21 um 17:55 schrieb Petr Vorel:
> > 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.
>
> Petr, where you able to reproduce this issue? Could the specifications of
> Jeff’s system be added to the commit message?
>
> > 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);
> > + 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";
>
> Now the non-block device case has one stat call more executed each time.
Practically this should not happen imho, as the device here are returned
by grub_guess_root_devices() to which underlying block devices is used
by a given path or mount point.
Thanks,
Michael
>
>
> Kind regards,
>
> Paul
>
[PATCH 1/2] osdep: Introduce major.h and use it, Petr Vorel, 2021/07/08