diff mbox series

[v2,1/2] common/rc: add _require_kernel_config and _has_kernel_config

Message ID 20211108210423.28980-1-lczerner@redhat.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] common/rc: add _require_kernel_config and _has_kernel_config | expand

Commit Message

Lukas Czerner Nov. 8, 2021, 9:04 p.m. UTC
Add _require_kernel_config() and _has_kernel_config() helpers to check
whether a specific kernel configuration is enabled on the kernel.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
v2: Document KCONFIG_PATH in README

 README        |  2 ++
 common/config |  1 +
 common/rc     | 29 +++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)

Comments

Darrick J. Wong Nov. 8, 2021, 10:31 p.m. UTC | #1
On Mon, Nov 08, 2021 at 10:04:23PM +0100, Lukas Czerner wrote:
> Add _require_kernel_config() and _has_kernel_config() helpers to check
> whether a specific kernel configuration is enabled on the kernel.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> v2: Document KCONFIG_PATH in README
> 
>  README        |  2 ++
>  common/config |  1 +
>  common/rc     | 29 +++++++++++++++++++++++++++++
>  3 files changed, 32 insertions(+)
> 
> diff --git a/README b/README
> index 63f0641a..e9284b22 100644
> --- a/README
> +++ b/README
> @@ -129,6 +129,8 @@ Preparing system for tests:
>                 xfs_check to check the filesystem.  As of August 2021,
>                 xfs_repair finds all filesystem corruptions found by xfs_check,
>                 and more, which means that xfs_check is no longer run by default.
> +	     - Set KCONFIG_PATH to specify your preferred location of kernel
> +	       config file.

The indentation here looks kind of off, but the core logic looks
correct.

With that fixed:
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

>  
>          - or add a case to the switch in common/config assigning
>            these variables based on the hostname of your test
> diff --git a/common/config b/common/config
> index 164381b7..e0a5c5df 100644
> --- a/common/config
> +++ b/common/config
> @@ -226,6 +226,7 @@ export OPENSSL_PROG="$(type -P openssl)"
>  export ACCTON_PROG="$(type -P accton)"
>  export E2IMAGE_PROG="$(type -P e2image)"
>  export BLKZONE_PROG="$(type -P blkzone)"
> +export GZIP_PROG="$(type -P gzip)"
>  
>  # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
>  # newer systems have udevadm command but older systems like RHEL5 don't.
> diff --git a/common/rc b/common/rc
> index 0d261184..84154868 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4703,6 +4703,35 @@ _require_names_are_bytes() {
>          esac
>  }
>  
> +_has_kernel_config()
> +{
> +	option=$1
> +	uname=$(uname -r)
> +	config_list="$KCONFIG_PATH
> +		     /proc/config.gz
> +		     /lib/modules/$uname/build/.config
> +		     /boot/config-$uname
> +		     /lib/kernel/config-$uname"
> +
> +	for config in $config_list; do
> +		[ ! -f $config ] && continue
> +		[ $config = "/proc/config.gz" ] && break
> +		grep -qE "^${option}=[my]" $config
> +		return
> +	done
> +
> +	[ ! -f $config ] && _notrun "Could not locate kernel config file"
> +
> +	# We can only get here with /proc/config.gz
> +	_require_command "$GZIP_PROG" gzip
> +	$GZIP_PROG -cd $config | grep -qE "^${option}=[my]"
> +}
> +
> +_require_kernel_config()
> +{
> +	_has_kernel_config $1 || _notrun "Installed kernel not built with $1"
> +}
> +
>  init_rc
>  
>  ################################################################################
> -- 
> 2.31.1
>
Lukas Czerner Nov. 9, 2021, 9:28 a.m. UTC | #2
On Mon, Nov 08, 2021 at 02:31:32PM -0800, Darrick J. Wong wrote:
> On Mon, Nov 08, 2021 at 10:04:23PM +0100, Lukas Czerner wrote:
> > Add _require_kernel_config() and _has_kernel_config() helpers to check
> > whether a specific kernel configuration is enabled on the kernel.
> > 
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > ---
> > v2: Document KCONFIG_PATH in README
> > 
> >  README        |  2 ++
> >  common/config |  1 +
> >  common/rc     | 29 +++++++++++++++++++++++++++++
> >  3 files changed, 32 insertions(+)
> > 
> > diff --git a/README b/README
> > index 63f0641a..e9284b22 100644
> > --- a/README
> > +++ b/README
> > @@ -129,6 +129,8 @@ Preparing system for tests:
> >                 xfs_check to check the filesystem.  As of August 2021,
> >                 xfs_repair finds all filesystem corruptions found by xfs_check,
> >                 and more, which means that xfs_check is no longer run by default.
> > +	     - Set KCONFIG_PATH to specify your preferred location of kernel
> > +	       config file.
> 
> The indentation here looks kind of off, but the core logic looks
> correct.

The file uses a mixture of tabs and spaces. In this case I used tabs,
the bullet point above uses spaces, that's why it looks kind of off in
the patch. Otherwise I used the same indentation as some other
bullet points so I don't think there is anything to fix in this patch.

> 
> With that fixed:
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Thanks for the review.
-Lukas

> 
> --D
> 
> >  
> >          - or add a case to the switch in common/config assigning
> >            these variables based on the hostname of your test
> > diff --git a/common/config b/common/config
> > index 164381b7..e0a5c5df 100644
> > --- a/common/config
> > +++ b/common/config
> > @@ -226,6 +226,7 @@ export OPENSSL_PROG="$(type -P openssl)"
> >  export ACCTON_PROG="$(type -P accton)"
> >  export E2IMAGE_PROG="$(type -P e2image)"
> >  export BLKZONE_PROG="$(type -P blkzone)"
> > +export GZIP_PROG="$(type -P gzip)"
> >  
> >  # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
> >  # newer systems have udevadm command but older systems like RHEL5 don't.
> > diff --git a/common/rc b/common/rc
> > index 0d261184..84154868 100644
> > --- a/common/rc
> > +++ b/common/rc
> > @@ -4703,6 +4703,35 @@ _require_names_are_bytes() {
> >          esac
> >  }
> >  
> > +_has_kernel_config()
> > +{
> > +	option=$1
> > +	uname=$(uname -r)
> > +	config_list="$KCONFIG_PATH
> > +		     /proc/config.gz
> > +		     /lib/modules/$uname/build/.config
> > +		     /boot/config-$uname
> > +		     /lib/kernel/config-$uname"
> > +
> > +	for config in $config_list; do
> > +		[ ! -f $config ] && continue
> > +		[ $config = "/proc/config.gz" ] && break
> > +		grep -qE "^${option}=[my]" $config
> > +		return
> > +	done
> > +
> > +	[ ! -f $config ] && _notrun "Could not locate kernel config file"
> > +
> > +	# We can only get here with /proc/config.gz
> > +	_require_command "$GZIP_PROG" gzip
> > +	$GZIP_PROG -cd $config | grep -qE "^${option}=[my]"
> > +}
> > +
> > +_require_kernel_config()
> > +{
> > +	_has_kernel_config $1 || _notrun "Installed kernel not built with $1"
> > +}
> > +
> >  init_rc
> >  
> >  ################################################################################
> > -- 
> > 2.31.1
> > 
>
Darrick J. Wong Nov. 9, 2021, 5:29 p.m. UTC | #3
On Tue, Nov 09, 2021 at 10:28:43AM +0100, Lukas Czerner wrote:
> On Mon, Nov 08, 2021 at 02:31:32PM -0800, Darrick J. Wong wrote:
> > On Mon, Nov 08, 2021 at 10:04:23PM +0100, Lukas Czerner wrote:
> > > Add _require_kernel_config() and _has_kernel_config() helpers to check
> > > whether a specific kernel configuration is enabled on the kernel.
> > > 
> > > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> > > ---
> > > v2: Document KCONFIG_PATH in README
> > > 
> > >  README        |  2 ++
> > >  common/config |  1 +
> > >  common/rc     | 29 +++++++++++++++++++++++++++++
> > >  3 files changed, 32 insertions(+)
> > > 
> > > diff --git a/README b/README
> > > index 63f0641a..e9284b22 100644
> > > --- a/README
> > > +++ b/README
> > > @@ -129,6 +129,8 @@ Preparing system for tests:
> > >                 xfs_check to check the filesystem.  As of August 2021,
> > >                 xfs_repair finds all filesystem corruptions found by xfs_check,
> > >                 and more, which means that xfs_check is no longer run by default.
> > > +	     - Set KCONFIG_PATH to specify your preferred location of kernel
> > > +	       config file.
> > 
> > The indentation here looks kind of off, but the core logic looks
> > correct.
> 
> The file uses a mixture of tabs and spaces. In this case I used tabs,
> the bullet point above uses spaces, that's why it looks kind of off in
> the patch. Otherwise I used the same indentation as some other
> bullet points so I don't think there is anything to fix in this patch.

LOL, so the last addition was from me?  Which added more inconsistent indent?

HA.  Objection withdrawn. :D

> > 
> > With that fixed:
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
> Thanks for the review.

NP.

--D

> -Lukas
> 
> > 
> > --D
> > 
> > >  
> > >          - or add a case to the switch in common/config assigning
> > >            these variables based on the hostname of your test
> > > diff --git a/common/config b/common/config
> > > index 164381b7..e0a5c5df 100644
> > > --- a/common/config
> > > +++ b/common/config
> > > @@ -226,6 +226,7 @@ export OPENSSL_PROG="$(type -P openssl)"
> > >  export ACCTON_PROG="$(type -P accton)"
> > >  export E2IMAGE_PROG="$(type -P e2image)"
> > >  export BLKZONE_PROG="$(type -P blkzone)"
> > > +export GZIP_PROG="$(type -P gzip)"
> > >  
> > >  # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
> > >  # newer systems have udevadm command but older systems like RHEL5 don't.
> > > diff --git a/common/rc b/common/rc
> > > index 0d261184..84154868 100644
> > > --- a/common/rc
> > > +++ b/common/rc
> > > @@ -4703,6 +4703,35 @@ _require_names_are_bytes() {
> > >          esac
> > >  }
> > >  
> > > +_has_kernel_config()
> > > +{
> > > +	option=$1
> > > +	uname=$(uname -r)
> > > +	config_list="$KCONFIG_PATH
> > > +		     /proc/config.gz
> > > +		     /lib/modules/$uname/build/.config
> > > +		     /boot/config-$uname
> > > +		     /lib/kernel/config-$uname"
> > > +
> > > +	for config in $config_list; do
> > > +		[ ! -f $config ] && continue
> > > +		[ $config = "/proc/config.gz" ] && break
> > > +		grep -qE "^${option}=[my]" $config
> > > +		return
> > > +	done
> > > +
> > > +	[ ! -f $config ] && _notrun "Could not locate kernel config file"
> > > +
> > > +	# We can only get here with /proc/config.gz
> > > +	_require_command "$GZIP_PROG" gzip
> > > +	$GZIP_PROG -cd $config | grep -qE "^${option}=[my]"
> > > +}
> > > +
> > > +_require_kernel_config()
> > > +{
> > > +	_has_kernel_config $1 || _notrun "Installed kernel not built with $1"
> > > +}
> > > +
> > >  init_rc
> > >  
> > >  ################################################################################
> > > -- 
> > > 2.31.1
> > > 
> > 
>
diff mbox series

Patch

diff --git a/README b/README
index 63f0641a..e9284b22 100644
--- a/README
+++ b/README
@@ -129,6 +129,8 @@  Preparing system for tests:
                xfs_check to check the filesystem.  As of August 2021,
                xfs_repair finds all filesystem corruptions found by xfs_check,
                and more, which means that xfs_check is no longer run by default.
+	     - Set KCONFIG_PATH to specify your preferred location of kernel
+	       config file.
 
         - or add a case to the switch in common/config assigning
           these variables based on the hostname of your test
diff --git a/common/config b/common/config
index 164381b7..e0a5c5df 100644
--- a/common/config
+++ b/common/config
@@ -226,6 +226,7 @@  export OPENSSL_PROG="$(type -P openssl)"
 export ACCTON_PROG="$(type -P accton)"
 export E2IMAGE_PROG="$(type -P e2image)"
 export BLKZONE_PROG="$(type -P blkzone)"
+export GZIP_PROG="$(type -P gzip)"
 
 # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled.
 # newer systems have udevadm command but older systems like RHEL5 don't.
diff --git a/common/rc b/common/rc
index 0d261184..84154868 100644
--- a/common/rc
+++ b/common/rc
@@ -4703,6 +4703,35 @@  _require_names_are_bytes() {
         esac
 }
 
+_has_kernel_config()
+{
+	option=$1
+	uname=$(uname -r)
+	config_list="$KCONFIG_PATH
+		     /proc/config.gz
+		     /lib/modules/$uname/build/.config
+		     /boot/config-$uname
+		     /lib/kernel/config-$uname"
+
+	for config in $config_list; do
+		[ ! -f $config ] && continue
+		[ $config = "/proc/config.gz" ] && break
+		grep -qE "^${option}=[my]" $config
+		return
+	done
+
+	[ ! -f $config ] && _notrun "Could not locate kernel config file"
+
+	# We can only get here with /proc/config.gz
+	_require_command "$GZIP_PROG" gzip
+	$GZIP_PROG -cd $config | grep -qE "^${option}=[my]"
+}
+
+_require_kernel_config()
+{
+	_has_kernel_config $1 || _notrun "Installed kernel not built with $1"
+}
+
 init_rc
 
 ################################################################################