[lttng-dev] [PATCH lttng-modules 1/4] Add extra version information framework

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Thu Jul 5 14:25:26 EDT 2018


Patch 1 merged into master, 2.10, 2.9,

Patches 2, 3, 4 merged into master,

Thanks!

Mathieu

----- On Jun 29, 2018, at 5:28 PM, Michael Jeanson mjeanson at efficios.com wrote:

> Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
> ---
> .gitignore                   |  2 ++
> Kbuild.common                | 14 +++++++++++
> extra-version-git.sh         | 20 +++++++++++++++
> extra-version-name.sh        | 13 ++++++++++
> extra-version-patches.sh     | 21 ++++++++++++++++
> extra_version/README         |  2 ++
> extra_version/patches/README |  2 ++
> lttng-events.c               | 49 +++++++++++++++++++++++++++++++-----
> 8 files changed, 117 insertions(+), 6 deletions(-)
> create mode 100755 extra-version-git.sh
> create mode 100755 extra-version-name.sh
> create mode 100755 extra-version-patches.sh
> create mode 100644 extra_version/README
> create mode 100644 extra_version/patches/README
> 
> diff --git a/.gitignore b/.gitignore
> index f22e828..38e1684 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -79,3 +79,5 @@ GTAGS
> *.orig
> *~
> \#*#
> +
> +/extra_version
> diff --git a/Kbuild.common b/Kbuild.common
> index c0d5409..bd24e80 100644
> --- a/Kbuild.common
> +++ b/Kbuild.common
> @@ -34,6 +34,20 @@ ifneq ($(RT_PATCH_VERSION), 0)
>   ccflags-y += -DRT_PATCH_VERSION=$(RT_PATCH_VERSION)
> endif
> 
> +EXTRA_VERSION_NAME:=$(shell $(TOP_LTTNG_MODULES_DIR)/extra-version-name.sh
> $(TOP_LTTNG_MODULES_DIR))
> +
> +ifneq ($(EXTRA_VERSION_NAME), 0)
> +  ccflags-y += -DLTTNG_EXTRA_VERSION_NAME='"$(EXTRA_VERSION_NAME)"'
> +endif
> +
> +EXTRA_VERSION_GIT:=$(shell $(TOP_LTTNG_MODULES_DIR)/extra-version-git.sh
> $(TOP_LTTNG_MODULES_DIR))
> +
> +ifneq ($(EXTRA_VERSION_GIT), 0)
> +  ccflags-y += -DLTTNG_EXTRA_VERSION_GIT='"$(EXTRA_VERSION_GIT)"'
> +endif
> +
> +EXTRA_VERSION_PATCHES:=$(shell
> $(TOP_LTTNG_MODULES_DIR)/extra-version-patches.sh $(TOP_LTTNG_MODULES_DIR))
> +
> # Starting with kernel 4.12, the ftrace header was moved to private headers
> # and as such is not available when building against distro headers instead
> # of the full kernel sources. In the situation, define
> LTTNG_FTRACE_MISSING_HEADER
> diff --git a/extra-version-git.sh b/extra-version-git.sh
> new file mode 100755
> index 0000000..e5a3e17
> --- /dev/null
> +++ b/extra-version-git.sh
> @@ -0,0 +1,20 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
> +
> +# First argument is the path to the lttng modules sources.
> +TOP_LTTNG_MODULES_DIR="$1"
> +
> +GIT_VERSION="0"
> +
> +if test -x "$(which git 2>&1;true)" && test -r "${TOP_LTTNG_MODULES_DIR}/.git";
> then
> +	GIT_VERSION_STR="$(cd "${TOP_LTTNG_MODULES_DIR}" && git describe --tags
> --dirty)"
> +	GIT_CURRENT_TAG="$(cd "${TOP_LTTNG_MODULES_DIR}" && git describe --tags
> --exact-match --match="v[0-9]*" HEAD 2> /dev/null)"
> +
> +	GIT_VERSION="${GIT_VERSION_STR}"
> +
> +	if ! echo "${GIT_VERSION_STR}" | grep -- "-dirty" >/dev/null && test
> "x$GIT_CURRENT_TAG" != "x"; then
> +		GIT_VERSION="0"
> +	fi
> +fi
> +
> +echo "${GIT_VERSION}"
> diff --git a/extra-version-name.sh b/extra-version-name.sh
> new file mode 100755
> index 0000000..f704256
> --- /dev/null
> +++ b/extra-version-name.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
> +
> +# First argument is the path to the lttng modules sources.
> +TOP_LTTNG_MODULES_DIR="$1"
> +
> +EXTRA_VERSION_NAME="$(sed -n '1p' "${TOP_LTTNG_MODULES_DIR}/extra_version/name"
> 2> /dev/null)"
> +
> +if [ "x${EXTRA_VERSION_NAME}" != "x" ]; then
> +	echo "${EXTRA_VERSION_NAME}"
> +else
> +	echo "0"
> +fi
> diff --git a/extra-version-patches.sh b/extra-version-patches.sh
> new file mode 100755
> index 0000000..4e8a1b5
> --- /dev/null
> +++ b/extra-version-patches.sh
> @@ -0,0 +1,21 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
> +
> +# First argument is the path to the lttng modules sources.
> +TOP_LTTNG_MODULES_DIR="$1"
> +
> +if ! test -d "${TOP_LTTNG_MODULES_DIR}"; then
> +	exit 1
> +fi
> +
> +TMPFILE="$(mktemp)"
> +
> +find "${TOP_LTTNG_MODULES_DIR}/extra_version/patches/" -maxdepth 1 ! -name
> 'README' -type f -printf '%f\n' | sort -r \
> +	| sed -E 's/[^a-zA-Z0-9 \.]/-/g ; s/(.*)/MODULE_INFO(extra_version_patch,
> "\1");/g' >"${TMPFILE}" 2>/dev/null
> +
> +if test ! -f "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i" || \
> +	test x"$(cat "${TMPFILE}")" != x"$(cat
> "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i")"; then
> +	mv "${TMPFILE}" "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i"
> +fi
> +
> +rm -f "${TMPFILE}"
> diff --git a/extra_version/README b/extra_version/README
> new file mode 100644
> index 0000000..5eef496
> --- /dev/null
> +++ b/extra_version/README
> @@ -0,0 +1,2 @@
> +The first line of the "name" file is used to populate the "extra_version_name"
> +modinfo key of each built module.
> diff --git a/extra_version/patches/README b/extra_version/patches/README
> new file mode 100644
> index 0000000..22ea3d3
> --- /dev/null
> +++ b/extra_version/patches/README
> @@ -0,0 +1,2 @@
> +The name of each file in this directory except this README will be used to
> +populate a "extra_version_path" modinfo key for each built module.
> diff --git a/lttng-events.c b/lttng-events.c
> index ec44502..c1f00ff 100644
> --- a/lttng-events.c
> +++ b/lttng-events.c
> @@ -2809,12 +2809,22 @@ static int __init lttng_events_init(void)
> 	ret = lttng_init_cpu_hotplug();
> 	if (ret)
> 		goto error_hotplug;
> -	printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)\n",
> +	printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
> 		__stringify(LTTNG_MODULES_MAJOR_VERSION),
> 		__stringify(LTTNG_MODULES_MINOR_VERSION),
> 		__stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
> 		LTTNG_MODULES_EXTRAVERSION,
> -		LTTNG_VERSION_NAME);
> +		LTTNG_VERSION_NAME,
> +#ifdef LTTNG_EXTRA_VERSION_GIT
> +		LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
> +#else
> +		"",
> +#endif
> +#ifdef LTTNG_EXTRA_VERSION_NAME
> +		LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
> +#else
> +		"");
> +#endif
> 	return 0;
> 
> error_hotplug:
> @@ -2827,12 +2837,22 @@ error_kmem:
> 	lttng_tracepoint_exit();
> error_tp:
> 	lttng_context_exit();
> -	printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)\n",
> +	printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
> 		__stringify(LTTNG_MODULES_MAJOR_VERSION),
> 		__stringify(LTTNG_MODULES_MINOR_VERSION),
> 		__stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
> 		LTTNG_MODULES_EXTRAVERSION,
> -		LTTNG_VERSION_NAME);
> +		LTTNG_VERSION_NAME,
> +#ifdef LTTNG_EXTRA_VERSION_GIT
> +		LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
> +#else
> +		"",
> +#endif
> +#ifdef LTTNG_EXTRA_VERSION_NAME
> +		LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
> +#else
> +		"");
> +#endif
> 	return ret;
> }
> 
> @@ -2850,16 +2870,33 @@ static void __exit lttng_events_exit(void)
> 	kmem_cache_destroy(event_cache);
> 	lttng_tracepoint_exit();
> 	lttng_context_exit();
> -	printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)\n",
> +	printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
> 		__stringify(LTTNG_MODULES_MAJOR_VERSION),
> 		__stringify(LTTNG_MODULES_MINOR_VERSION),
> 		__stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
> 		LTTNG_MODULES_EXTRAVERSION,
> -		LTTNG_VERSION_NAME);
> +		LTTNG_VERSION_NAME,
> +#ifdef LTTNG_EXTRA_VERSION_GIT
> +		LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
> +#else
> +		"",
> +#endif
> +#ifdef LTTNG_EXTRA_VERSION_NAME
> +		LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
> +#else
> +		"");
> +#endif
> }
> 
> module_exit(lttng_events_exit);
> 
> +#include "extra_version/patches.i"
> +#ifdef LTTNG_EXTRA_VERSION_GIT
> +MODULE_INFO(extra_version_git, LTTNG_EXTRA_VERSION_GIT);
> +#endif
> +#ifdef LTTNG_EXTRA_VERSION_NAME
> +MODULE_INFO(extra_version_name, LTTNG_EXTRA_VERSION_NAME);
> +#endif
> MODULE_LICENSE("GPL and additional rights");
> MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers at efficios.com>");
> MODULE_DESCRIPTION("LTTng Events");
> --
> 2.17.1

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list