linux: use stat instead of udevadm for partition lookup + cleanup
cover linux: use stat instead of udevadm for partition lookup + cleanup
Hi,
I'm backporting Jeff's patch from openSUSE + adding little cleanup.
Kind regards,
Petr
Jeff Mahoney (1):
grub2: use stat instead of udevadm for partition lookup
Petr Vorel (1):
osdep: Introduce major.h and use it
grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/linux/hostdisk.c | 8 ++++++++ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 6 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
Signature · 1 line
2.32.0
PATCH 1/2 osdep: Introduce major.h and use it
--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
grub-core/osdep/devmapper/getroot.c +1 -6
@@ -40,12 +40,7 @@#include <limits.h> #endif -#if defined(MAJOR_IN_MKDEV ) -#include <sys/mkdev.h> -#elif defined(MAJOR_IN_SYSMACROS ) -#include <sys/sysmacros.h> -#endif - +#include <grub/osdep/major.h> #include <libdevmapper.h> #include <grub/types.h>
grub-core/osdep/devmapper/hostdisk.c +1 -6
@@ -11,6 +11,7 @@#include <grub/misc.h> #include <grub/i18n.h> #include <grub/list.h> +#include <grub/osdep/major.h> #include <stdio.h> #include <stdlib.h>
@@ -24,12 +25,6 @@#include <errno.h> #include <limits.h> -#if defined(MAJOR_IN_MKDEV ) -#include <sys/mkdev.h> -#elif defined(MAJOR_IN_SYSMACROS ) -#include <sys/sysmacros.h> -#endif -#ifdef HAVE_DEVICE_MAPPER # include <libdevmapper.h>
grub-core/osdep/linux/getroot.c +1 -6
@@ -35,12 +35,7 @@#include <limits.h> #endif -#if defined(MAJOR_IN_MKDEV ) -#include <sys/mkdev.h> -#elif defined(MAJOR_IN_SYSMACROS ) -#include <sys/sysmacros.h> -#endif - +#include <grub/osdep/major.h> #include <grub/types.h> #include <sys/ioctl.h> /* ioctl */ #include <sys/mount.h>
grub-core/osdep/unix/getroot.c +1 -6
@@ -51,12 +51,7 @@#endif /* ! FLOPPY_MAJOR */ #endif -#include <sys/types.h> -#if defined(MAJOR_IN_MKDEV ) -#include <sys/mkdev.h> -#elif defined(MAJOR_IN_SYSMACROS ) -#include <sys/sysmacros.h> -#endif +#include <grub/osdep/major.h> #if defined(HAVE_LIBZFS ) && defined(HAVE_LIBNVPAIR )# include <grub/util/libzfs.h>
include/grub/osdep/major.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2021 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* Fix for glibc 2.25 is deprecating the namespace pollution of sys/types.h +* injecting major(), minor(), and makedev() into the compilation environment. +* See configure.ac. +*/ + +#include <sys/types.h> +#ifdef MAJOR_IN_MKDEV +# include <sys/mkdev.h> +#elif defined(MAJOR_IN_SYSMACROS ) +# include <sys/sysmacros.h> +#endif
Signature · 1 line
2.32.0
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Quoted 9 lines · Petr Vorel
Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
May I ask you to explain in the commit message why this patch is needed?
Daniel
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Quoted 11 lines · Petr Vorel
Quoted 9 lines
Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
Quoted 1 line
May I ask you to explain in the commit message why this patch is needed?
It's just a small cleanup. If you're not against it, sure, I can mention it in the commit message.
Kind regards,
Petr
Quoted 1 line
Daniel
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Hi Daniel,
Quoted 11 lines
Quoted 10 lines · Petr Vorel
Quoted 9 lines
Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
Quoted 3 lines
Quoted 1 line
May I ask you to explain in the commit message why this patch is needed?
It's just a small cleanup. If you're not against it, sure, I can mention it in the commit message.
Ah, you probably mean to put the description from major.h also to the commit message.
Kind regards,
Petr
+/*
+ * Fix for glibc 2.25 is deprecating the namespace pollution of sys/types.h
+ * injecting major(), minor(), and makedev() into the compilation environment.
+ * See configure.ac.
+*/
Quoted 4 lines
Kind regards,
PetrQuoted 1 line
Daniel
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Quoted 16 lines · Petr Vorel
Hi Daniel,
Quoted 14 lines
Quoted 11 lines · Petr Vorel
Quoted 9 lines
Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.hQuoted 1 line
May I ask you to explain in the commit message why this patch is needed?
It's just a small cleanup. If you're not against it, sure, I can mention it in the commit message.
I am OK with the cleanup.
Quoted 2 lines
Ah, you probably mean to put the description from
major.halso to the commit message.
To some extent. I think it should be phrased a bit better in the commit message.
Quoted 7 lines
Kind regards,
Petr+/*
+ * Fix for glibc 2.25 is deprecating the namespace pollution ofsys/types.h
+ * injectingmajor(),minor(), andmakedev()into the compilation environment.
+ * See configure.ac.
It seems to me "See configure.ac." is not relevant in the GRUB source. So, probably it should be replaced with some text from glibc configure.ac.
Daniel
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Hi Daniel,
Quoted 14 lines · Petr Vorel
Quoted 12 lines
Hi Daniel,
Quoted 10 lines
Quoted 10 lines · Petr Vorel
Quoted 9 lines
Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/devmapper/getroot.c | 7 +------ grub-core/osdep/devmapper/hostdisk.c | 7 +------ grub-core/osdep/linux/getroot.c | 7 +------ grub-core/osdep/unix/getroot.c | 7 +------ include/grub/osdep/major.h | 30 ++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 include/grub/osdep/major.h
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
May I ask you to explain in the commit message why this patch is needed?
It's just a small cleanup. If you're not against it, sure, I can mention it in the commit message.
I am OK with the cleanup.
thx for ack!
Quoted 4 lines
Quoted 2 lines
Ah, you probably mean to put the description from
major.halso to the commit message.To some extent. I think it should be phrased a bit better in the commit message.
sure.
Quoted 10 lines
Quoted 7 lines
Kind regards,
Petr+/*
+ * Fix for glibc 2.25 is deprecating the namespace pollution ofsys/types.h
+ * injectingmajor(),minor(), andmakedev()into the compilation environment.
+ * See configure.ac.It seems to me "See configure.ac." is not relevant in the GRUB source. So, probably it should be replaced with some text from glibc configure.ac.
I didn't know how to link AC_HEADER_MAJOR with include/grub/osdep/major.h. Because in the future when glibc 2.25 is old enough the header will be removed and AC_HEADER_MAJOR might be left in configure.ac (name is different from MAJOR_IN_{MKDEV,SYSMACROS}). But I can note this in commit message instead.
Kind regards,
Petr
Quoted 1 line
Daniel
Re: [PATCH 1/2] osdep: Introduce major.h and use it
Hi Daniel,
...
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
+/*
+ * Fix for glibc 2.25 is deprecating the namespace pollution ofsys/types.h
+ * injectingmajor(),minor(), andmakedev()into the compilation environment.
+ * See configure.ac.
Quoted 7 lines
Quoted 2 lines
It seems to me "See configure.ac." is not relevant in the GRUB source. So, probably it should be replaced with some text from glibc configure.ac.
I didn't know how to link
AC_HEADER_MAJORwithinclude/grub/osdep/major.h. Because in the future when glibc 2.25 is old enough the header will be removed andAC_HEADER_MAJORmight be left in configure.ac (name is different from MAJOR_IN_{MKDEV,SYSMACROS}). But I can note this in commit message instead.
But thinking about it twice also note in configure.ac instead (+ commit message) would be good. But that's just a minor detail.
Kind regards,
Petr
Quoted 4 lines
Kind regards,
PetrQuoted 1 line
Daniel
PATCH 2/2 grub2: use stat instead of udevadm for partition lookup
In reply to Petr VorelFrom: Jeff Mahoney <[email protected]>
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.
--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)
grub-core/osdep/linux/hostdisk.c +8 -0
@@ -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" ;
Signature · 1 line
2.32.0
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Dear Petr, dear Jeff,
Am 08.07.21 um 17:55 schrieb Petr Vorel:
Quoted 8 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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?
Quoted 23 lines
Signed-off-by Jeff Mahoney <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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 ;
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 10 lines
grub-core/osdep/linux/hostdisk.c +7
-0+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.
Kind regards,
Paul
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Hi Paul,
Quoted 6 lines
Dear Petr, dear Jeff,
Am 08.07.21 um 17:55 schrieb Petr Vorel:
Quoted 1 line
From: Jeff Mahoney <[email protected]>
Quoted 8 lines
Quoted 6 lines
sysfs_partition_pathcalls 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?
No, I'm sorry, I haven't even tried, because accessing sysfs seems to me as a quickest way anyway. But agree that we drag this patch in opensuse from 2017 (for 2.02~rc1), it might not be relevant for nowadays systems.
Quoted 1 line
Could the specifications of Jeff’s system be added to the commit message?
Jeff, Michael, could you verify if it's still relevant?
Kind regards,
Petr
Quoted 38 lines
Quoted 21 lines
Signed-off-by Jeff Mahoney <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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 ;grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 117
Quoted 10 lines
grub-core/osdep/linux/hostdisk.c +7
-0char *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.
Kind regards,
Paul
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Quoted 15 lines · Petr Vorel
Hi Paul,
Quoted 12 lines
Dear Petr, dear Jeff,
Am 08.07.21 um 17:55 schrieb Petr Vorel:
Quoted 8 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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.
Quoted 7 lines
Quoted 1 line
Petr, where you able to reproduce this issue?
No, I'm sorry, I haven't even tried, because accessing sysfs seems to me as a quickest way anyway. But agree that we drag this patch in opensuse from 2017 (for 2.02~rc1), it might not be relevant for nowadays systems.
Quoted 1 line
Could the specifications of Jeff’s system be added to the commit message?
Jeff, Michael, could you verify if it's still relevant?
It is still relevant per my test, although not as considerable as Jeff's system.
I was using openSUSE Tumbleweed, pretty much all defaults and simple, btrfs as root file system without any abstraction disks (lvm, mdadm and encryption).
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 663M 0 rom vda 253:0 0 20G 0 disk vda1 253:1 0 1.4G 0 part [SWAP] vda2 253:2 0 18.6G 0 part /
The output of time grub2-mkconfig -o /boot/grub2/grub.cfg with the patch applied.
real 0m1.292s user 0m0.782s sys 0m0.427s
and without
real 0m2.323s user 0m1.295s sys 0m0.956s
This cuts the execution to somewhere near 55%, which is pretty signifcant.
Please note if testing on lvm, there wouldn't have difference on the execution time as libdevmapper is used instead of udevadm to get the partition start.
Thanks,
Michael
Quoted 43 lines
Kind regards,
PetrQuoted 38 lines
Quoted 21 lines
Signed-off-by Jeff Mahoney <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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 ;grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 117
Quoted 10 lines
grub-core/osdep/linux/hostdisk.c +7
-0char *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.
Kind regards,
Paul
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Hi Michael,
Quoted 44 lines · Petr Vorel
Quoted 15 lines
Hi Paul,
Quoted 12 lines
Dear Petr, dear Jeff,
Am 08.07.21 um 17:55 schrieb Petr Vorel:
Quoted 8 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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.
Quoted 7 lines
Quoted 1 line
Petr, where you able to reproduce this issue?
No, I'm sorry, I haven't even tried, because accessing sysfs seems to me as a quickest way anyway. But agree that we drag this patch in opensuse from 2017 (for 2.02~rc1), it might not be relevant for nowadays systems.
Quoted 1 line
Could the specifications of Jeff’s system be added to the commit message?
Jeff, Michael, could you verify if it's still relevant?
It is still relevant per my test, although not as considerable as Jeff's system.
I was using openSUSE Tumbleweed, pretty much all defaults and simple, btrfs as root file system without any abstraction disks (lvm, mdadm and encryption).
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 663M 0 rom vda 253:0 0 20G 0 disk vda1 253:1 0 1.4G 0 part [SWAP] vda2 253:2 0 18.6G 0 part /The output of
time grub2-mkconfig -o /boot/grub2/grub.cfgwith the patch applied.real 0m1.292s user 0m0.782s sys 0m0.427s
Quoted 7 lines
and without
real 0m2.323s user 0m1.295s sys 0m0.956sThis cuts the execution to somewhere near 55%, which is pretty signifcant.
Thanks a lot for testing. I'll send v2 shortly.
Quoted 3 lines
Please note if testing on lvm, there wouldn't have difference on the execution time as libdevmapper is used instead of udevadm to get the partition start.
Good to know (some of my system have lvm).
Kind regards,
Petr
Quoted 2 lines
Thanks,
Michael
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
In reply to Paul MenzelQuoted 41 lines · Paul Menzel
Dear Petr, dear Jeff,
Am 08.07.21 um 17:55 schrieb Petr Vorel:
Quoted 8 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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?
Quoted 25 lines
Signed-off-by Jeff Mahoney <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +4
-0@@ -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; +
Quoted 8 lines
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 6 lines
grub-core/osdep/linux/hostdisk.c +4
-0+ 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
Quoted 6 lines
Kind regards,
Paul
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
In reply to Petr VorelQuoted 29 lines · Petr Vorel
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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 <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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>
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 112
Quoted 7 lines
grub-core/osdep/linux/hostdisk.c +4
-0@@ -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 "(".
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 113
Quoted 1 line
grub-core/osdep/linux/hostdisk.c +1
-0+if (ret ==0 &&S_ISBLK (st.st_mode))
Same for S_ISBLK...
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 5 lines
grub-core/osdep/linux/hostdisk.c +2
-0+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.
Daniel
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Quoted 44 lines · Daniel Kiper
Quoted 29 lines · Petr Vorel
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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 <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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> grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 112
Quoted 7 lines
grub-core/osdep/linux/hostdisk.c +4
-0@@ -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 "(".
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 113
Quoted 1 line
grub-core/osdep/linux/hostdisk.c +1
-0+if (ret ==0 &&S_ISBLK (st.st_mode))Same for
S_ISBLK...
Quoted 8 lines
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 5 lines
grub-core/osdep/linux/hostdisk.c +2
-0+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.
-Jeff
Signature · 2 lines
Jeff Mahoney Director, SUSE Labs Data & Performance
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Hi all,
Quoted 54 lines · Daniel Kiper
Quoted 44 lines · Petr Vorel
Quoted 29 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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 <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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> grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 112
Quoted 7 lines
grub-core/osdep/linux/hostdisk.c +4
-0@@ -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 "(".
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 113
Quoted 1 line
grub-core/osdep/linux/hostdisk.c +1
-0+if (ret ==0 &&S_ISBLK (st.st_mode))Same for
S_ISBLK...Quoted 8 lines
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 5 lines
grub-core/osdep/linux/hostdisk.c +2
-0+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.
Quoted 7 lines
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
Quoted 1 line
-Jeff
Re: [PATCH 2/2] grub2: use stat instead of udevadm for partition lookup
Quoted 64 lines · Petr Vorel
Hi all,
Quoted 54 lines · Daniel Kiper
Quoted 44 lines · Petr Vorel
Quoted 29 lines
From: Jeff Mahoney <[email protected]>
sysfs_partition_pathcalls 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 <[email protected]>[ pvorel: include grub/osdep/major.h ]Signed-off-by Petr Vorel <[email protected]>--- grub-core/osdep/linux/hostdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/osdep/linux/hostdisk.c +1
-0@@ -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> grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 112
Quoted 7 lines
grub-core/osdep/linux/hostdisk.c +4
-0@@ -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 "(".
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 113
Quoted 1 line
grub-core/osdep/linux/hostdisk.c +1
-0+if (ret ==0 &&S_ISBLK (st.st_mode))Same for
S_ISBLK...Quoted 8 lines
grub-core/osdep/linux/hostdisk.c sysfs_partition_path (const char *dev, const char *entry) · line 118
Quoted 5 lines
grub-core/osdep/linux/hostdisk.c +2
-0+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.
Quoted 7 lines
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.
Quoted 2 lines
As it'd be wort to remove udevadm fallback, I'll stop being lazy and setup VM to test.
Please do. I prefer to remove this fallback because it will be mostly dead code after your fix.
Daniel