overlay coreos/{user-patches,config}: Overrides for thin-provisioning-tools

Let's avoid pulling in clang, shall we?

Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
This commit is contained in:
Krzesimir Nowak 2025-11-17 16:07:21 +01:00
parent 529b598e15
commit fbb0d0ca71
4 changed files with 236 additions and 0 deletions

View File

@ -0,0 +1,2 @@
# This is to disable building thin_migrate tool.
export ECARGO_EXTRA_ARGS=--no-default-features

View File

@ -0,0 +1,81 @@
From c5fbb32be0509e4368268a79e7aacc6b5e34d28e Mon Sep 17 00:00:00 2001
From: Krzesimir Nowak <knowak@microsoft.com>
Date: Thu, 20 Nov 2025 13:16:09 +0100
Subject: [PATCH 1/2] [build] Simplify installation of symlinks and manpages
Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
---
Makefile | 52 ++++++++--------------------------------------------
1 file changed, 8 insertions(+), 44 deletions(-)
diff --git a/Makefile b/Makefile
index b04937aa..44c99c99 100644
--- a/Makefile
+++ b/Makefile
@@ -55,55 +55,19 @@ TOOLS:=\
era_invalidate \
era_restore
+# This must be two empty lines to get a newline.
+define NEWLINE
+
+
+endef
+
MANPAGES:=$(patsubst %,man8/%.8,$(TOOLS))
install: $(MANPAGES)
$(INSTALL_DIR) $(BINDIR)
$(INSTALL_PROGRAM) $(PDATA_TOOLS) $(BINDIR)
- ln -s -f pdata_tools $(BINDIR)/cache_check
- ln -s -f pdata_tools $(BINDIR)/cache_dump
- ln -s -f pdata_tools $(BINDIR)/cache_metadata_size
- ln -s -f pdata_tools $(BINDIR)/cache_repair
- ln -s -f pdata_tools $(BINDIR)/cache_restore
- ln -s -f pdata_tools $(BINDIR)/cache_writeback
- ln -s -f pdata_tools $(BINDIR)/thin_check
- ln -s -f pdata_tools $(BINDIR)/thin_delta
- ln -s -f pdata_tools $(BINDIR)/thin_dump
- ln -s -f pdata_tools $(BINDIR)/thin_ls
- ln -s -f pdata_tools $(BINDIR)/thin_repair
- ln -s -f pdata_tools $(BINDIR)/thin_restore
- ln -s -f pdata_tools $(BINDIR)/thin_rmap
- ln -s -f pdata_tools $(BINDIR)/thin_metadata_size
- ln -s -f pdata_tools $(BINDIR)/thin_metadata_pack
- ln -s -f pdata_tools $(BINDIR)/thin_metadata_unpack
- ln -s -f pdata_tools $(BINDIR)/thin_migrate
- ln -s -f pdata_tools $(BINDIR)/thin_trim
- ln -s -f pdata_tools $(BINDIR)/era_check
- ln -s -f pdata_tools $(BINDIR)/era_dump
- ln -s -f pdata_tools $(BINDIR)/era_invalidate
- ln -s -f pdata_tools $(BINDIR)/era_restore
+ $(foreach tool, $(TOOLS), ln -s -f pdata_tools $(BINDIR)/$(tool); $(NEWLINE))
$(INSTALL_DIR) $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_check.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_dump.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_metadata_size.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_repair.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_restore.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/cache_writeback.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_check.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_delta.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_dump.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_ls.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_repair.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_restore.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_rmap.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_metadata_size.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_metadata_pack.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_metadata_unpack.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_migrate.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/era_check.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/era_dump.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/era_restore.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/era_invalidate.8 $(MANPATH)/man8
- $(INSTALL_DATA) man8/thin_trim.8 $(MANPATH)/man8
+ $(foreach tool, $(TOOLS), $(INSTALL_DATA) man8/$(tool).8 $(MANPATH)/man8; $(NEWLINE))
.PHONY: install
--
2.51.2

View File

@ -0,0 +1,135 @@
From 74215dade7bbddbfc0a46e1903fc289a56df3915 Mon Sep 17 00:00:00 2001
From: Krzesimir Nowak <knowak@microsoft.com>
Date: Thu, 20 Nov 2025 13:17:36 +0100
Subject: [PATCH 2/2] [all] Make thin_migrate tool optional
The tool pulls in, indirectly through the devicemapper crate, a
dependency on libclang. Make it possible to skip the tool to avoid the
dependency, but keep it enabled by default.
Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
---
Cargo.toml | 4 +++-
Makefile | 20 ++++++++++++++++++--
src/bin/pdata_tools.rs | 1 +
src/commands/mod.rs | 1 +
src/thin/mod.rs | 1 +
5 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 8594c6ba..155285a8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,7 +18,7 @@ clap = { version = "4.5", default-features = false, features = [
] }
crc32c = "0.6"
data-encoding = "2.9"
-devicemapper = "0.34"
+devicemapper ={ version = "0.34", optional = true }
exitcode = "1.1.2"
fixedbitset = "0.5"
flate2 = "1.1"
@@ -51,9 +51,11 @@ tempfile = "3.23"
thinp = { path = ".", features = ["devtools"] }
[features]
+default = ["thin_migrate"]
devtools = ["ratatui", "termion"]
io_uring = ["dep:io-uring"]
no_cleanup = []
+thin_migrate = ["dep:devicemapper"]
[profile.release]
debug = true
diff --git a/Makefile b/Makefile
index 44c99c99..a2dd51a4 100644
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,10 @@ V=@
PDATA_TOOLS:=\
target/release/pdata_tools
+CARGO_FLAGS:=$(if $(DISABLE_THIN_MIGRATE),--no-default-features)
$(PDATA_TOOLS):
- $(V) cargo build --release
+ $(V) cargo build --release $(CARGO_FLAGS)
PREFIX:=/usr
BINDIR:=$(DESTDIR)$(PREFIX)/sbin
@@ -31,6 +32,21 @@ clean:
cargo clean
$(RM) man8/*.8
+HAS_PDATA_TOOLS_BINARY:=$(shell if [ -f $(PDATA_TOOLS) ]; then echo 1; fi)
+ifneq ($(HAS_PDATA_TOOLS_BINARY),)
+
+HAS_THIN_MIGRATE:=$(shell grep -qF thin_migrate.rs $(PDATA_TOOLS).d && echo 1)
+
+ifneq ($(DISABLE_THIN_MIGRATE),)
+$(warning DISABLE_THIN_MIGRATE variable is ignored, the pdata_tools binary exists and it has $(if $(HAS_THIN_MIGRATE),,no )thin_migrate tool built in)
+endif
+
+else
+
+HAS_THIN_MIGRATE:=$(if $(DISABLE_THIN_MIGRATE),,1)
+
+endif
+
TOOLS:=\
cache_check \
cache_dump \
@@ -42,13 +58,13 @@ TOOLS:=\
thin_delta \
thin_dump \
thin_ls \
+ $(if $(HAS_THIN_MIGRATE),thin_migrate) \
thin_repair \
thin_restore \
thin_rmap \
thin_metadata_size \
thin_metadata_pack \
thin_metadata_unpack \
- thin_migrate \
thin_trim \
era_check \
era_dump \
diff --git a/src/bin/pdata_tools.rs b/src/bin/pdata_tools.rs
index c288fe03..67ef0d7d 100644
--- a/src/bin/pdata_tools.rs
+++ b/src/bin/pdata_tools.rs
@@ -29,6 +29,7 @@ fn register_commands<'a>() -> Vec<Box<dyn Command<'a>>> {
Box::new(thin_metadata_pack::ThinMetadataPackCommand),
Box::new(thin_metadata_size::ThinMetadataSizeCommand),
Box::new(thin_metadata_unpack::ThinMetadataUnpackCommand),
+ #[cfg(feature = "thin_migrate")]
Box::new(thin_migrate::ThinMigrateCommand),
Box::new(thin_repair::ThinRepairCommand),
Box::new(thin_restore::ThinRestoreCommand),
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 5eeb66ab..72481eba 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -17,6 +17,7 @@ pub mod thin_ls;
pub mod thin_metadata_pack;
pub mod thin_metadata_size;
pub mod thin_metadata_unpack;
+#[cfg(feature = "thin_migrate")]
pub mod thin_migrate;
pub mod thin_repair;
pub mod thin_restore;
diff --git a/src/thin/mod.rs b/src/thin/mod.rs
index 1ef0e1be..eeed031e 100644
--- a/src/thin/mod.rs
+++ b/src/thin/mod.rs
@@ -10,6 +10,7 @@ pub mod ls;
pub mod metadata;
pub mod metadata_repair;
pub mod metadata_size;
+#[cfg(feature = "thin_migrate")]
pub mod migrate;
pub mod repair;
pub mod restore;
--
2.51.2

View File

@ -0,0 +1,18 @@
The patches make the thin_migrate tool optional, as this seems to be
the thing that pulls in devicemapper crate, which in order requires
bindgen crate, which in turn depends on libclang. Since thin_migrate
tools was never a part of Flatcar yet, we can skip building it for
now. If users will need the tool, we can think about adding it at a
cost of building clang in SDK builds.
The patches were filed to upstream:
https://github.com/device-mapper-utils/thin-provisioning-tools/pull/1
If they get accepted, we can try convincing Gentoo to add
"USE=+migrate" to the ebuild and hide the clang dependency behind the
flag. On Flatcar side we could then disable it.
Until that happens, these patches should be accompanied by a hook
function that will do "export ECARGO_EXTRA_ARGS=--no-default-features"
and "export MAKEOPTS=THIN_MIGRATE_EXCLUDE=x".