Blame SOURCES/0003-system_id-new-appmachineid-option.patch

9db2f0
From 8b83c056d12b32cffa15a77423b6be9748c0ede1 Mon Sep 17 00:00:00 2001
9db2f0
From: David Teigland <teigland@redhat.com>
9db2f0
Date: Wed, 20 May 2020 10:59:38 -0500
9db2f0
Subject: [PATCH 03/11] system_id: new appmachineid option
9db2f0
9db2f0
The new system_id_source="appmachineid" will cause
9db2f0
lvm to use an lvm-specific derivation of the machine-id,
9db2f0
instead of the machine-id directly.  This is now
9db2f0
recommended in place of using machineid.
9db2f0
---
9db2f0
 configure.ac                 | 20 ++++++++++++++++++++
9db2f0
 lib/commands/toolcontext.c   | 26 +++++++++++++++++++++++---
9db2f0
 lib/config/config_settings.h |  8 +++++---
9db2f0
 man/lvmsystemid.7_main       | 17 +++++++++++++++++
9db2f0
 test/shell/system_id.sh      | 11 +++++++++++
9db2f0
 5 files changed, 76 insertions(+), 6 deletions(-)
9db2f0
9db2f0
diff --git a/configure.ac b/configure.ac
9db2f0
index a20633e..9fe50e1 100644
9db2f0
--- a/configure.ac
9db2f0
+++ b/configure.ac
9db2f0
@@ -1105,6 +1105,26 @@ if test "$NOTIFYDBUS_SUPPORT" = yes; then
9db2f0
 fi
9db2f0
 
9db2f0
 ################################################################################
9db2f0
+dnl -- Build appmachineid
9db2f0
+AC_MSG_CHECKING(whether to build appmachineid)
9db2f0
+AC_ARG_ENABLE(app-machineid,
9db2f0
+	      AC_HELP_STRING([--enable-app-machineid],
9db2f0
+			     [enable LVM system ID using app-specific machine-id]),
9db2f0
+	      APP_MACHINEID_SUPPORT=$enableval, APP_MACHINEID_SUPPORT=no)
9db2f0
+AC_MSG_RESULT($APP_MACHINEID_SUPPORT)
9db2f0
+
9db2f0
+if test "$APP_MACHINEID_SUPPORT" = yes; then
9db2f0
+	AC_DEFINE([APP_MACHINEID_SUPPORT], 1, [Define to 1 to include code that uses libsystemd machine-id apis.])
9db2f0
+	SYSTEMD_LIBS="-lsystemd"
9db2f0
+fi
9db2f0
+
9db2f0
+################################################################################
9db2f0
+dnl -- Look for libsystemd libraries
9db2f0
+if test "$APP_MACHINEID_SUPPORT" = yes; then
9db2f0
+	PKG_CHECK_MODULES(APP_MACHINEID, systemd >= 234, [HAVE_APP_MACHINEID=yes], $bailout)
9db2f0
+fi
9db2f0
+
9db2f0
+################################################################################
9db2f0
 
9db2f0
 dnl -- Enable blkid wiping functionality
9db2f0
 AC_ARG_ENABLE(blkid_wiping,
9db2f0
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
9db2f0
index ecd50db..8991aeb 100644
9db2f0
--- a/lib/commands/toolcontext.c
9db2f0
+++ b/lib/commands/toolcontext.c
9db2f0
@@ -41,6 +41,10 @@
9db2f0
 #include <syslog.h>
9db2f0
 #include <time.h>
9db2f0
 
9db2f0
+#ifdef APP_MACHINEID_SUPPORT
9db2f0
+#include <systemd/sd-id128.h>
9db2f0
+#endif
9db2f0
+
9db2f0
 #ifdef __linux__
9db2f0
 #  include <malloc.h>
9db2f0
 #endif
9db2f0
@@ -129,9 +133,12 @@ static const char *_read_system_id_from_file(struct cmd_context *cmd, const char
9db2f0
 	return system_id;
9db2f0
 }
9db2f0
 
9db2f0
+/* systemd-id128 new produced: f64406832c2140e8ac5422d1089aae03 */
9db2f0
+#define LVM_APPLICATION_ID SD_ID128_MAKE(f6,44,06,83,2c,21,40,e8,ac,54,22,d1,08,9a,ae,03)
9db2f0
+
9db2f0
 static const char *_system_id_from_source(struct cmd_context *cmd, const char *source)
9db2f0
 {
9db2f0
-	char filebuf[PATH_MAX];
9db2f0
+	char buf[PATH_MAX];
9db2f0
 	const char *file;
9db2f0
 	const char *etc_str;
9db2f0
 	const char *str;
9db2f0
@@ -150,10 +157,23 @@ static const char *_system_id_from_source(struct cmd_context *cmd, const char *s
9db2f0
 		goto out;
9db2f0
 	}
9db2f0
 
9db2f0
+#ifdef APP_MACHINEID_SUPPORT
9db2f0
+	if (!strcasecmp(source, "appmachineid")) {
9db2f0
+		sd_id128_t id;
9db2f0
+
9db2f0
+		sd_id128_get_machine_app_specific(LVM_APPLICATION_ID, &id;;
9db2f0
+
9db2f0
+		if (dm_snprintf(buf, PATH_MAX, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id)) < 0)
9db2f0
+			stack;
9db2f0
+		system_id = system_id_from_string(cmd, buf);
9db2f0
+		goto out;
9db2f0
+	}
9db2f0
+#endif
9db2f0
+
9db2f0
 	if (!strcasecmp(source, "machineid") || !strcasecmp(source, "machine-id")) {
9db2f0
 		etc_str = find_config_tree_str(cmd, global_etc_CFG, NULL);
9db2f0
-		if (dm_snprintf(filebuf, sizeof(filebuf), "%s/machine-id", etc_str) != -1)
9db2f0
-			system_id = _read_system_id_from_file(cmd, filebuf);
9db2f0
+		if (dm_snprintf(buf, sizeof(buf), "%s/machine-id", etc_str) != -1)
9db2f0
+			system_id = _read_system_id_from_file(cmd, buf);
9db2f0
 		goto out;
9db2f0
 	}
9db2f0
 
9db2f0
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
9db2f0
index 9cf73ce..76ebc10 100644
9db2f0
--- a/lib/config/config_settings.h
9db2f0
+++ b/lib/config/config_settings.h
9db2f0
@@ -1273,10 +1273,12 @@ cfg(global_system_id_source_CFG, "system_id_source", global_CFG_SECTION, CFG_DEF
9db2f0
 	"  uname\n"
9db2f0
 	"    Set the system ID from the hostname (uname) of the system.\n"
9db2f0
 	"    System IDs beginning localhost are not permitted.\n"
9db2f0
+	"  appmachineid\n"
9db2f0
+	"    Use an LVM-specific derivation of the local machine-id as the\n"
9db2f0
+	"    system ID. See 'man machine-id'.\n"
9db2f0
 	"  machineid\n"
9db2f0
-	"    Use the contents of the machine-id file to set the system ID.\n"
9db2f0
-	"    Some systems create this file at installation time.\n"
9db2f0
-	"    See 'man machine-id' and global/etc.\n"
9db2f0
+	"    Use the contents of the machine-id file to set the system ID\n"
9db2f0
+	"    (appmachineid is recommended.)\n"
9db2f0
 	"  file\n"
9db2f0
 	"    Use the contents of another file (system_id_file) to set the\n"
9db2f0
 	"    system ID.\n"
9db2f0
diff --git a/man/lvmsystemid.7_main b/man/lvmsystemid.7_main
9db2f0
index eac4f7b..06e7f34 100644
9db2f0
--- a/man/lvmsystemid.7_main
9db2f0
+++ b/man/lvmsystemid.7_main
9db2f0
@@ -173,6 +173,22 @@ global {
9db2f0
 .fi
9db2f0
 .
9db2f0
 .TP
9db2f0
+.B appmachineid
9db2f0
+.br
9db2f0
+
9db2f0
+An LVM-specific derivation of /etc/machine-id is used as the system ID.
9db2f0
+See
9db2f0
+.BR machine-id (5)
9db2f0
+to check if machine-id is available on the host.
9db2f0
+
9db2f0
+.I lvm.conf
9db2f0
+.nf
9db2f0
+global {
9db2f0
+    system_id_source = "appmachineid"
9db2f0
+}
9db2f0
+.fi
9db2f0
+
9db2f0
+.TP
9db2f0
 .B machineid
9db2f0
 .br
9db2f0
 The content of /etc/machine-id is used as the system ID if available.
9db2f0
@@ -181,6 +197,7 @@ See
9db2f0
 and
9db2f0
 .BR systemd-machine-id-setup (1)
9db2f0
 to check if machine-id is available on the host.
9db2f0
+(appmachineid is recommended in place of machineid.)
9db2f0
 .sp
9db2f0
 .I lvm.conf
9db2f0
 .nf
9db2f0
diff --git a/test/shell/system_id.sh b/test/shell/system_id.sh
9db2f0
index 8814d54..8b5638a 100644
9db2f0
--- a/test/shell/system_id.sh
9db2f0
+++ b/test/shell/system_id.sh
9db2f0
@@ -50,6 +50,17 @@ check vg_field $vg1 systemid "$SID"
9db2f0
 vgremove $vg1
9db2f0
 fi
9db2f0
 
9db2f0
+## appmachineid
9db2f0
+lvm version > lvmver
9db2f0
+if grep app-machineid lvmver; then
9db2f0
+aux lvmconf "global/system_id_source = appmachineid"
9db2f0
+lvm systemid | awk '{ print $3 }' > sid_lvm
9db2f0
+vgcreate $vg1 "$dev1"
9db2f0
+vgs -o systemid --noheadings $vg1 | awk '{print $1}' > sid_vg
9db2f0
+diff sid_lvm sid_vg
9db2f0
+vgremove $vg1
9db2f0
+fi
9db2f0
+
9db2f0
 ## uname
9db2f0
 
9db2f0
 SID1=$(uname -n)
9db2f0
-- 
9db2f0
1.8.3.1
9db2f0