From: Michael Jeanson Date: Fri, 29 Jun 2018 21:28:30 +0000 (-0400) Subject: Add extra version information framework X-Git-Tag: v2.9.10~4 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=31b00794a30ea27fdf0c14f4885df500fb28a099;p=lttng-modules.git Add extra version information framework Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/.gitignore b/.gitignore index f22e828e..38e16841 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,5 @@ GTAGS *.orig *~ \#*# + +/extra_version diff --git a/Makefile.ABI.workarounds b/Makefile.ABI.workarounds index fcd980de..04b223a8 100644 --- a/Makefile.ABI.workarounds +++ b/Makefile.ABI.workarounds @@ -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 00000000..e5a3e176 --- /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 00000000..f7042567 --- /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 00000000..4e8a1b52 --- /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 00000000..5eef496d --- /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 00000000..22ea3d37 --- /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 5e9c72bf..04df65c6 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -2807,6 +2807,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)%s%s\n", + __stringify(LTTNG_MODULES_MAJOR_VERSION), + __stringify(LTTNG_MODULES_MINOR_VERSION), + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), + LTTNG_MODULES_EXTRAVERSION, + 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: @@ -2819,6 +2835,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)%s%s\n", + __stringify(LTTNG_MODULES_MAJOR_VERSION), + __stringify(LTTNG_MODULES_MINOR_VERSION), + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), + LTTNG_MODULES_EXTRAVERSION, + 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; } @@ -2836,10 +2868,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)%s%s\n", + __stringify(LTTNG_MODULES_MAJOR_VERSION), + __stringify(LTTNG_MODULES_MINOR_VERSION), + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION), + LTTNG_MODULES_EXTRAVERSION, + 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 "); MODULE_DESCRIPTION("LTTng Events");