Make the blscfg sort order match what grub2 and grubby do.

Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
Peter Jones 2018-10-15 13:57:18 -04:00 committed by Dan Horák
parent 2f4b67cd1e
commit c301cb59af
3 changed files with 158 additions and 4 deletions

View File

@ -0,0 +1,148 @@
From 8ec7b75204f3c7bf691e14b89c73c5dd28d2a824 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 15 Oct 2018 13:54:16 -0400
Subject: [PATCH] blscfg: sort like rpm nvr, not like a single version
Signed-off-by: Peter Jones <pjones@redhat.com>
---
zipl/src/scan.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++-
zipl/src/Makefile | 3 +-
2 files changed, 96 insertions(+), 3 deletions(-)
diff --git a/zipl/src/scan.c b/zipl/src/scan.c
index fe72e9ab13d..63186222783 100644
--- a/zipl/src/scan.c
+++ b/zipl/src/scan.c
@@ -33,6 +33,8 @@
#include "lib/util_base.h"
+#include <rpm/rpmlib.h>
+
#include "boot.h"
#include "error.h"
#include "misc.h"
@@ -652,14 +654,104 @@ bls_filter(const struct dirent *ent)
return strncmp(ent->d_name + offset, ".conf", strlen(".conf")) == 0;
}
+/* returns name/version/release */
+/* NULL string pointer returned if nothing found */
+static void
+split_package_string (char *package_string, char **name,
+ char **version, char **release)
+{
+ char *package_version, *package_release;
+
+ /* Release */
+ package_release = strrchr (package_string, '-');
+
+ if (package_release != NULL)
+ *package_release++ = '\0';
+
+ *release = package_release;
+
+ /* Version */
+ package_version = strrchr(package_string, '-');
+
+ if (package_version != NULL)
+ *package_version++ = '\0';
+
+ *version = package_version;
+ /* Name */
+ *name = package_string;
+
+ /* Bubble up non-null values from release to name */
+ if (name != NULL && *name == NULL) {
+ *name = (*version == NULL ? *release : *version);
+ *version = *release;
+ *release = NULL;
+ }
+ if (*version == NULL) {
+ *version = *release;
+ *release = NULL;
+ }
+}
+
+static int
+split_cmp(char *nvr0, char *nvr1, int has_name)
+{
+ int ret = 0;
+ char *name0, *version0, *release0;
+ char *name1, *version1, *release1;
+
+ split_package_string(nvr0, has_name ? &name0 : NULL, &version0, &release0);
+ split_package_string(nvr1, has_name ? &name1 : NULL, &version1, &release1);
+
+ if (has_name) {
+ ret = rpmvercmp(name0 == NULL ? "" : name0,
+ name1 == NULL ? "" : name1);
+ if (ret != 0)
+ return ret;
+ }
+
+ ret = rpmvercmp(version0 == NULL ? "" : version0,
+ version1 == NULL ? "" : version1);
+ if (ret != 0)
+ return ret;
+
+ ret = rpmvercmp(release0 == NULL ? "" : release0,
+ release1 == NULL ? "" : release1);
+ return ret;
+}
+
+/* return 1: filename0 is newer than filename1 */
+/* 0: filename0 and filename1 are the same version */
+/* -1: filename1 is newer than filename0 */
+static int bls_cmp(const char *filename0, const char *filename1)
+{
+ char *id0, *id1;
+ int l, r;
+
+ id0 = strdup(filename0);
+ id1 = strdup(filename1);
+
+ l = strlen(id0);
+ if (l > 5 && strcmp(id0 + l - 5, ".conf"))
+ id0[l-5] = '\0';
+
+ l = strlen(id1);
+ if (l > 5 && strcmp(id1 + l - 5, ".conf"))
+ id1[l-5] = '\0';
+
+ r = split_cmp(id0, id1, 1);
+
+ free(id0);
+ free(id1);
+
+ return r;
+}
static int
bls_sort(const struct dirent **ent_a, const struct dirent **ent_b)
{
- return strverscmp((*ent_a)->d_name, (*ent_b)->d_name);
+ return bls_cmp((*ent_a)->d_name, (*ent_b)->d_name);
}
-
static int
scan_append_section_heading(struct scan_token* scan, int* index, char* name);
static int
diff --git a/zipl/src/Makefile b/zipl/src/Makefile
index 1634c0d5121..bc797990652 100644
--- a/zipl/src/Makefile
+++ b/zipl/src/Makefile
@@ -11,7 +11,8 @@ ALL_CPPFLAGS += -I../include -I../boot \
ALL_LDFLAGS += -Wl,-z,noexecstack $(NO_PIE_LDFLAGS)
libs = $(rootdir)/libutil/libutil.a \
- $(rootdir)/libu2s/libu2s.a
+ $(rootdir)/libu2s/libu2s.a \
+ -lrpm
objects = misc.o error.o scan.o job.o boot.o bootmap.o disk.o \
install.o zipl.o $(rootdir)/zipl/boot/data.o
--
2.17.1

View File

@ -106,12 +106,11 @@ case "$COMMAND" in
fi fi
if [ "x${MAKEDEBUG}" = "xyes" ]; then if [ "x${MAKEDEBUG}" = "xyes" ]; then
ARCH="$(uname -m)" BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/\.${ARCH}/-debug.${ARCH}/")"
cp -aT "${BLS_TARGET}" "${BLS_DEBUG}" cp -aT "${BLS_TARGET}" "${BLS_DEBUG}"
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')" TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
VERSION="$(grep '^version[ \t]' "${BLS_DEBUG}" | sed -e 's/^version[ \t]*//')" VERSION="$(grep '^version[ \t]' "${BLS_DEBUG}" | sed -e 's/^version[ \t]*//')"
BLSID="$(grep '^id[ \t]' "${BLS_DEBUG}" | sed -e "s/\.${ARCH}/-debug.${ARCH}/")" BLSID="$(grep '^id[ \t]' "${BLS_DEBUG}" | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
sed -i -e "s/^title.*/title ${TITLE}${LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}" sed -i -e "s/^title.*/title ${TITLE}${LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}"
sed -i -e "s/^version.*/version ${VERSION}${LINUX_DEBUG_VERSION_POSTFIX}/" "${BLS_DEBUG}" sed -i -e "s/^version.*/version ${VERSION}${LINUX_DEBUG_VERSION_POSTFIX}/" "${BLS_DEBUG}"
sed -i -e "s/^id.*/${BLSID}/" "${BLS_DEBUG}" sed -i -e "s/^id.*/${BLSID}/" "${BLS_DEBUG}"

View File

@ -5,7 +5,7 @@ Name: s390utils
Summary: Utilities and daemons for IBM z Systems Summary: Utilities and daemons for IBM z Systems
Group: System Environment/Base Group: System Environment/Base
Version: 2.6.0 Version: 2.6.0
Release: 6%{?dist} Release: 7%{?dist}
Epoch: 2 Epoch: 2
License: MIT License: MIT
ExclusiveArch: s390 s390x ExclusiveArch: s390 s390x
@ -35,6 +35,7 @@ Patch0: s390-tools-zipl-invert-script-options.patch
Patch1: s390-tools-zipl-fiemap.patch Patch1: s390-tools-zipl-fiemap.patch
# https://github.com/ibm-s390-tools/s390-tools/pull/35 # https://github.com/ibm-s390-tools/s390-tools/pull/35
Patch2: s390-tools-cleanup.patch Patch2: s390-tools-cleanup.patch
Patch3: 0007-blscfg-sort-like-rpm-nvr-not-like-a-single-version.patch
Patch1000: cmsfs-1.1.8-warnings.patch Patch1000: cmsfs-1.1.8-warnings.patch
Patch1001: cmsfs-1.1.8-kernel26.patch Patch1001: cmsfs-1.1.8-kernel26.patch
@ -49,6 +50,7 @@ Requires: s390utils-ziomon = %{epoch}:%{version}-%{release}
Requires: s390utils-cmsfs = %{epoch}:%{version}-%{release} Requires: s390utils-cmsfs = %{epoch}:%{version}-%{release}
BuildRequires: gcc-c++ BuildRequires: gcc-c++
BuildRequires: rpm-devel
%description %description
This is a meta package for installing the default s390-tools sub packages. This is a meta package for installing the default s390-tools sub packages.
@ -65,6 +67,7 @@ be used together with the zSeries (s390) Linux kernel and device drivers.
%patch0 -p1 -b .zipl-invert-script-options %patch0 -p1 -b .zipl-invert-script-options
%patch1 -p1 -b .zipl-fiemap %patch1 -p1 -b .zipl-fiemap
%patch2 -p1 -b .cleanup %patch2 -p1 -b .cleanup
%patch3 -p1 -b .blscfg-rpm-nvr-sort
# #
# cmsfs # cmsfs
@ -810,6 +813,10 @@ User-space development files for the s390/s390x architecture.
%changelog %changelog
* Mon Oct 15 2018 Peter Jones <pjones@redhat.com> - 2.6.0-7
- Make the blscfg sort order match what grub2 and grubby do. (pjones)
- Add a ~debug suffix instead of -debug to sort it correctly. (javierm)
* Mon Oct 01 2018 Dan Horák <dan[at]danny.cz> - 2:2.6.0-6 * Mon Oct 01 2018 Dan Horák <dan[at]danny.cz> - 2:2.6.0-6
- Fix kernel-install scripts issues - Fix kernel-install scripts issues