Skip to content

Comments

Make thin_migrate tool optional#1

Open
krnowak wants to merge 2 commits intodevice-mapper-utils:mainfrom
flatcar-hub:krnowak/optional-migrate
Open

Make thin_migrate tool optional#1
krnowak wants to merge 2 commits intodevice-mapper-utils:mainfrom
flatcar-hub:krnowak/optional-migrate

Conversation

@krnowak
Copy link

@krnowak krnowak commented Nov 20, 2025

Please consider making the aforementioned tool optional, but still enabled by default. The tool pulls in a dependency on libclang through devicemapper crate and it would be nice to skip it if possible.

In Flatcar we kept using version 1.0.10 to avoid building clang just for this one package. If possible, we would still like to keep it out. I came up with this patch, because our upstream (Gentoo) dropped this rather old version of the package.

Currently, the thin_migrate tool is behind the "migrate" feature, and installation of the symlink is can be disabled with the non-empty THIN_MIGRATE_EXCLUDE variable in Makefile.

Copy link

@mingnus mingnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I had considered this cleanup when modifying Makefile previously, but it ended up slipping through. Appreciate you addressing it.

Makefile Outdated
ln -s -f pdata_tools $(BINDIR)/era_dump
ln -s -f pdata_tools $(BINDIR)/era_invalidate
ln -s -f pdata_tools $(BINDIR)/era_restore
for tool in $(TOOLS); do ln -s -f pdata_tools $(BINDIR)/$${tool}; done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind using the foreach function instead for better logging and portability?

$(foreach tool, $(TOOLS), ln -s -f pdata_tools $(BINDIR)/$(tool); $(NEWLINE))

Also define the NEWLINE variable in Makefile to separate the lines:

define NEWLINE


endef

Makefile Outdated
$(INSTALL_DATA) man8/era_restore.8 $(MANPATH)/man8
$(INSTALL_DATA) man8/era_invalidate.8 $(MANPATH)/man8
$(INSTALL_DATA) man8/thin_trim.8 $(MANPATH)/man8
for tool in $(TOOLS); do $(INSTALL_DATA) man8/$${tool}.8 $(MANPATH)/man8; done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly,

$(foreach tool,$(TOOLS), $(INSTALL_DATA) man8/$(tool).8 $(MANPATH)/man8; $(NEWLINE))

Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
@krnowak krnowak force-pushed the krnowak/optional-migrate branch from fd3d574 to d560748 Compare November 24, 2025 15:37
@krnowak
Copy link
Author

krnowak commented Nov 24, 2025

Thanks for the review. Replaced the bash loop with make loop. I also added a slightly-unrelated commit fixing a warning in txt2man that was showing up for every generated man-page - I must have updated something in the meantime, because I haven't seen it before.

Copy link

@mingnus mingnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review provided. I'm wondering why clang is avoided. Is that due to build errors or some other constraint?

Cargo.toml Outdated
thinp = { path = ".", features = ["devtools"] }

[features]
default = ["migrate"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming the feature to thin_migrate for clarity?

Makefile Outdated
era_invalidate \
era_restore

ifeq ($(THIN_MIGRATE_EXCLUDE),)
Copy link

@mingnus mingnus Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider naming this DISABLE_THIN_MIGRATE to align with how the configure script handles naming?

Also, the flag should be propagate to the build command as well:

CARGO_FLAGS:=$(if $(DISABLE_THIN_MIGRATE),--no-default-features)

$(PDATA_TOOLS):
	$(V) cargo build --release $(CARGO_FLAGS)

Given that users may run cargo build and make install separately, the feature availability check should be performed when the binary exists:

HAS_THIN_MIGRATE:=$(shell if [ -f $(PDATA_TOOLS) ]; then \
	$(PDATA_TOOLS) 2>&1 | grep -q thin_migrate && echo 1; \
else \
	$(if $(DISABLE_THIN_MIGRATE), true, echo 1); \
fi)

Finally, enable thin_migrate installation accordingly:

TOOLS:=\
	...
	era_restore \
	$(if $(HAS_THIN_MIGRATE),thin_migrate)

(Both $(if and ifeq could be acceptable. I'm using $(if to make it consistent with the previous section)

That means, the DISABLE_THIN_MIGRATE flag doesn't affect the installation if the binary was built with thin_migrate enabled, or vise versa.

Copy link
Author

@krnowak krnowak Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider naming this DISABLE_THIN_MIGRATE to align with how the configure script handles naming?

Sure, sounds good.

Also, the flag should be propagate to the build command as well:

CARGO_FLAGS:=$(if $(DISABLE_THIN_MIGRATE),--no-default-features)

$(PDATA_TOOLS):
	$(V) cargo build --release $(CARGO_FLAGS)

Alright.

Given that users may run cargo build and make install separately, the feature availability check should be performed when the binary exists:

HAS_THIN_MIGRATE:=$(shell if [ -f $(PDATA_TOOLS) ]; then \
	$(PDATA_TOOLS) 2>&1 | grep -q thin_migrate && echo 1; \
else \
	$(if $(DISABLE_THIN_MIGRATE), true, echo 1); \
fi)

We are cross-compiling thin-provisioning-tools, so running $(PDATA_TOOLS) to check if migrate appears in the output won't work for us. Also, I'd print a warning about DISABLE_THIN_MIGRATE being ignored if the binary already exists. How about the following?

HAS_THIN_MIGRATE:=$(shell if [ -f $(PDATA_TOOLS).d ]; then \
	grep -qF thin-migrate.rs $(PDATA_TOOLS).d && echo 1; \
else \
	$(if $(DISABLE_THIN_MIGRATE), true, echo 2); \
fi)
ifeq ($(HAS_THIN_MIGRATE),2)
ifneq ($(DISABLE_THIN_MIGRATE),)
$(warning DISABLE_THIN_MIGRATE variable is ignored, the pdata_tools binary exists and it has thin_migrate tool built in) 
endif
endif

The $(PDATA_TOOLS).d seems to be some dependency file that lists all the source files that were used to build the binary. So if there is thin_migrate.rs listed, then it means that thin_migrate tool was built.

Finally, enable thin_migrate installation accordingly:

TOOLS:=\
	...
	era_restore \
	$(if $(HAS_THIN_MIGRATE),thin_migrate)

(Both $(if and ifeq could be acceptable. I'm using $(if to make it consistent with the previous section)

That means, the DISABLE_THIN_MIGRATE flag doesn't affect the installation if the binary was built with thin_migrate enabled, or vise versa.

bin/txt2man Outdated
sub(/^ +$/,"")
}
/^[:space:]*[[:upper:][:digit:]]+[[:upper:][:space:][:digit:][:punct:]]+$/ {
/^[[:space:]]*[[:upper:][:digit:]]+[[:upper:][:space:][:digit:][:punct:]]+$/ {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks reasonable to me. However, I cannot reproduce the warning using gawk 5.3.0. Could you please let me know which version of gawk is reporting this warning? Also, would you mind reporting this issue to the txt2man upstream as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using gawk 5.3.2. Also, this seems to be already reported: mvertes/txt2man#41 and my fix is probably not correct, see upstream commit with the fix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll revert this commit for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the upstream commit was reverted too, so no fix yet. Probably a regression in gawk.

Copy link

@mingnus mingnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the second commit

@krnowak
Copy link
Author

krnowak commented Nov 25, 2025

Review provided. I'm wondering why clang is avoided. Is that due to build errors or some other constraint?

Just trying to avoid pulling in clang into Flatcar's SDK solely for the thin_migrate tool, which we didn't have so far, so seems like our users don't need it.

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>
@krnowak krnowak force-pushed the krnowak/optional-migrate branch from d560748 to 32daf1b Compare November 25, 2025 16:07
@krnowak
Copy link
Author

krnowak commented Nov 25, 2025

Updated.

@mingnus
Copy link

mingnus commented Nov 25, 2025

My concern is that disabling a high-level feature like thin_migrate doesn't solve the dependency issue for the whole project, as the bindgen & clang dependency is indirect (introduced by devicemapper-rs), and the devicemapper library may be used by other tools in the future.

If the goal is to provide a way to build without bindgen & clang, I believe a better approach would be to provide a minimal devicemapper wrapper with pre-generated bindings, thus eliminating the need for bindgen and clang at compile time. A feature flag will be used to toggle between the default devicemapper-rs and the minimal wrapper implementations.

What are your thoughts on this approach?

@chewi
Copy link

chewi commented Nov 25, 2025

I did consider something like that myself, but I ruled it out because it wouldn't have been feasible for Flatcar to do it by itself, and then we saw that it only affected thin_migrate anyway. If you're happy to handle this upstream, that would be ideal. I don't think there would be any compatibility issues as the headers are bundled with devicemapper-rs.

@mingnus
Copy link

mingnus commented Nov 26, 2025

Understood. I will start investigating the necessary changes, but expect this to take some time. I'll provide updates here.

@mingnus
Copy link

mingnus commented Dec 19, 2025

@krnowak I'm drafting the fix. Since the Cargo features are strict additive, we'll have to specify the --no-default-features option to avoid compiling the default devicemapper-rs dependency, e.g.,

# use the internal devicemapper implementation
cargo build --no-default-features --features internal-dm

Does this necessity align with how you plan to integrate the crate?

@chewi
Copy link

chewi commented Dec 19, 2025

@krnowak is away at the moment, but I've checked Gentoo's cargo.eclass, and it allows for conditionally enabling features as well as passing --no-default-features, so please go ahead. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants