package/lvm2: enable package with musl
PATCH 1/1 package/lvm2: enable package with musl
LVM uses some glibc-specific functions to try and control locking memory in RAM. As a result the package is currently disabled when using musl.
Apply patches taken from gentoo:
https://github.com/gentoo/gentoo/pull/25883 https://github.com/gentoo/gentoo/pull/26024
and drop the prohibition on musl in Config.in.
--- .../lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch | 25 +++++++++++ ...002-lvm2-2.03.14-r1-fopen-to-freopen.patch | 44 +++++++++++++++++++ .../lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch | 20 +++++++++ .../lvm2/0004-lvm2-2.03.14-freopen_n2.patch | 36 +++++++++++++++ package/lvm2/Config.in | 5 --- 5 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch create mode 100644 package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch create mode 100644 package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch create mode 100644 package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch
package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch new file +25 -0
@@ -0,0 +1,25 @@ +https://bugs.gentoo.org/712336 +https://bugs.gentoo.org/549506 + +Adds fcntl.h into daemon-server.c to define fcntl and some constants. + +Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694 +--- + libdaemon/server/daemon-server.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c +index 88905a7..771b021 100644 +--- a/libdaemon/server/daemon-server.c ++++ b/libdaemon/server/daemon-server.c +@@ -28,6 +28,7 @@ + #include <sys/un.h> + #include <unistd.h> + #include <signal.h> ++#include <fcntl.h> + + #include <syslog.h> /* FIXME. For the global closelog(). */ + +-- +2.35.1 +
package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch new file +44 -0
44 lines not on this page · raw message
package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch new file +20 -0
@@ -0,0 +1,20 @@ +https://git.alpinelinux.org/aports/tree/main/lvm2/mallinfo.patch + +Patch from Alpine, disables _allocate_memory since mallinfo isn't defined in musl. +19:17 <@sam_> your caution is well-advised, but it should be safe enough given it's only affecting the non-glibc path + +Should be looked back to! + +Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694 + +--- ./lib/mm/memlock.c.orig 2015-03-09 11:18:41.560028850 -0100 ++++ ./lib/mm/memlock.c 2015-03-09 11:19:54.504373309 -0100 +@@ -137,7 +137,7 @@ + + static void _allocate_memory(void) + { +-#ifndef VALGRIND_POOL ++#if !defined(VALGRIND_POOL) && defined(__GLIBC__) + void *stack_mem; + struct rlimit limit; + int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch new file +36 -0
@@ -0,0 +1,36 @@ +In musl, the standard streams are read-only. To modify them we need to +use freopen. This patch does the same as lvm2-2.03.14-r1-fopen-to-freopen.patch + +https://listman.redhat.com/archives/lvm-devel/2022-June/024203.html + +See also: +https://wiki.gentoo.org/wiki/User:Sam/Musl_porting_notes#error:_assignment_of_read-only_variable_.27.5Bstdout.7Cstdin.7Cstderr.5D.27 +https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html + +Fetch from: http://listman.redhat.com/archives/lvm-devel/attachments/20220621/3594a4a7/attachment.bin + +--- + lib/log/log.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/lib/log/log.c b/lib/log/log.c +index 7b4d537..897c183 100644 +--- a/lib/log/log.c ++++ b/lib/log/log.c +@@ -207,8 +207,12 @@ int reopen_standard_stream(FILE **stream, const char *mode) + } + + _check_and_replace_standard_log_streams(old_stream, new_stream); +- ++ ++#ifdef __GLIBC__ + *stream = new_stream; ++#else ++ freopen(NULL, mode, *stream); ++#endif + return 1; + } + +-- +2.35.1 +
package/lvm2/Config.in +0 -5
@@ -27,15 +27,10 @@ if BR2_PACKAGE_LVM2 config BR2_PACKAGE_LVM2_STANDARD_INSTALL bool "standard install instead of only dmsetup" default y - # http://lists.busybox.net/pipermail/buildroot/2016-August/170592.html - depends on !BR2_TOOLCHAIN_USES_MUSL help Install the standard suite of lvm2 programs. When this option is not set, only dmsetup is installed. -comment "lvm2 standard install needs a glibc or uClibc toolchain" - depends on BR2_TOOLCHAIN_USES_MUSL - endif comment "lvm2 needs a toolchain w/ threads, dynamic library"
Signature · 6 lines
2.22.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Simon,
Quoted 4 lines · On Thu, 16 Mar 2023 11:36:15 +0000 Simon Rowe <[email protected]> wrote:
LVM uses some glibc-specific functions to try and control locking memory in RAM. As a result the package is currently disabled when using musl.
Quoted 8 lines
Apply patches taken from gentoo:
https://github.com/gentoo/gentoo/pull/25883 https://github.com/gentoo/gentoo/pull/26024and drop the prohibition on musl in Config.in.
Signed-off-by Simon Rowe <[email protected]>
Thanks Simon for those patches! Could you rework the 4 patches so that they are generated with git format-patch and have your Signed-off-by? I recommend that you take the upstream Git repo of lvm2, checkout the tag corresponding to version 2.03.14, apply the 4 Gentoo patches, each time turning the changes into a proper commit.
Another thing to look at is that the multipath-tools package is selecting BR2_PACKAGE_LVM2_STANDARD_INSTALL, so you need to check whether the depends on !BR2_TOOLCHAIN_USES_MUSL used in BR2_PACKAGE_MULTIPATH_TOOLS is still needed? Perhaps thanks to your work on lvm2 it is now possible to build/use multipath-tools with musl.
Another question is the upstream status of the Gentoo patches? Have they been submitted for inclusion by the upstream lvm2 project?
Thanks!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 5 lines · On 19 March 2023 Thomas Petazzoni wrote:
Thanks Simon for those patches! Could you rework the 4 patches so that they are generated with git format-patch and have your Signed-off-by? I recommend that you take the upstream Git repo of lvm2, checkout the tag corresponding to version 2.03.14, apply the 4 Gentoo patches, each time turning the changes into a proper commit.
I am not the author of these patches, which is why I didn’t add a ‘Signed-off-by:’. I followed what I thought the process was for patches originating from elsewhere by adding a ‘Fetch from:’ to each patch as mentioned in 19.4 of the manual. I can regenerate them if that’s the correct approach.
Quoted 5 lines
Another thing to look at is that the multipath-tools package is selecting
BR2_PACKAGE_LVM2_STANDARD_INSTALL, so you need to check whether the depends on !BR2_TOOLCHAIN_USES_MUSL used inBR2_PACKAGE_MULTIPATH_TOOLSis still needed? Perhaps thanks to your work on lvm2 it is now possible to build/use multipath-tools with musl.
I’ve not got a use case for multipath myself by I’ll check if I can get it to build with these patches.
Quoted 2 lines
Another question is the upstream status of the Gentoo patches? Have they been submitted for inclusion by the upstream lvm2 project?
There seems to be a suggestion that was attempted on the ticket
https://bugs.gentoo.org/549506
but that was some time ago and there’s no sign of them being accepted.
Regards
Simon
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Simon,
Quoted 5 lines · On Tue, 21 Mar 2023 13:39:12 +0000 Simon Rowe <[email protected]> wrote:
I am not the author of these patches, which is why I didn’t add a ‘Signed-off-by:’. I followed what I thought the process was for patches originating from elsewhere by adding a ‘Fetch from:’ to each patch as mentioned in 19.4 of the manual. I can regenerate them if that’s the correct approach.
A Signed-off-by is not only an indication of the author, but also an indication of the chain of people through which the patch traveled. For example in the Linux kernel, patches have a SoB from the author, then a SoB from the maintainer taking the patch, and possibly another SoB from yet another maintainer taking the patch from that previous maintainer.
In Buildroot, we therefore have patches with two SoB: one from the original author, and one from the developer bringing the patch into Buildroot. Or alternatively patches with only one SoB, from the developer bringing the patch into Buildroot (you in this case) when the original patch lacks an SoB.
Quoted 2 lines
I’ve not got a use case for multipath myself by I’ll check if I can get it to build with these patches.
Good!
Quoted 8 lines
Quoted 2 lines
Another question is the upstream status of the Gentoo patches? Have they been submitted for inclusion by the upstream lvm2 project?
There seems to be a suggestion that was attempted on the ticket
https://bugs.gentoo.org/549506
but that was some time ago and there’s no sign of them being accepted.
It's been a while ago. Perhaps time to do another attempt at upstreaming those patches?
Thanks a lot!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 11 lines · On 21 March 2023 Thomas Petazzoni wrote:
A Signed-off-by is not only an indication of the author, but also an indication of the chain of people through which the patch traveled. For example in the Linux kernel, patches have a SoB from the author, then a SoB from the maintainer taking the patch, and possibly another SoB from yet another maintainer taking the patch from that previous maintainer.
In Buildroot, we therefore have patches with two SoB: one from the original author, and one from the developer bringing the patch into Buildroot. Or alternatively patches with only one SoB, from the developer bringing the patch into Buildroot (you in this case) when the original patch lacks an SoB.
Thank you for explaining this, I’ll add the SoB to the new series.
Quoted 2 lines
It's been a while ago. Perhaps time to do another attempt at upstreaming those patches?
After a little more research I’ve discovered that some of the fixes are covered by changesets present in the upstream master. I’ll replace my patches with those and try to upstream the remainder.
I’ve confirmed that multipath-tools builds with musl so I’ll include a patch for this. I’ve not tested if the resulting binary works though.
Regards
Simon
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 10 lines · On Thu, 23 Mar 2023 12:36:54 +0000 Simon Rowe <[email protected]> wrote:
Quoted 2 lines
It's been a while ago. Perhaps time to do another attempt at upstreaming those patches?
After a little more research I’ve discovered that some of the fixes are covered by changesets present in the upstream master. I’ll replace my patches with those and try to upstream the remainder.
I’ve confirmed that multipath-tools builds with musl so I’ll include a patch for this. I’ve not tested if the resulting binary works though.
This is all great news. Thanks a lot for the extra work, looking forward to seeing the patches!
Best regards,
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 1/2 package/lvm2: enable package with musl
In reply to Simon RoweLVM relies on the glibc-specific behaviour of assigning to the standard streams (stdin etc). As a result the package is currently disabled when using musl.
Apply patches based on those present in gentoo:
https://github.com/gentoo/gentoo/pull/25883 https://github.com/gentoo/gentoo/pull/26024
and drop the prohibition on musl in Config.in.
Also, backport a couple of compilation fixes needed build with musl.
--- ...sible-better-compilation-with-musl-c.patch | 30 +++++++++ ...m-preallocate-memory-only-with-glibc.patch | 34 ++++++++++ ...e-freopen-to-reopen-standard-streams.patch | 67 +++++++++++++++++++ ...e-freopen-to-reopen-standard-streams.patch | 43 ++++++++++++ package/lvm2/Config.in | 5 -- 5 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch create mode 100644 package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch create mode 100644 package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch create mode 100644 package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch
package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch new file +30 -0
@@ -0,0 +1,30 @@ +From bac596b3685520acaa404dc3ebd2131e6de96d47 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac <[email protected]> +Date: Wed, 16 Feb 2022 00:48:49 +0100 +Subject: [PATCH] clang: possible better compilation with musl c + +Try to help resolving reported compilation problem with +clang & musl C. +https://github.com/lvmteam/lvm2/issues/61 + +Backported from: 4fd76de4b69f8e5e6d5afa03d54cb4b8986c4bcc +Signed-off-by: Simon Rowe <[email protected]> +--- + libdaemon/server/daemon-server.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c +index 88905a7dd..96cfc392e 100644 +--- a/libdaemon/server/daemon-server.c ++++ b/libdaemon/server/daemon-server.c +@@ -18,6 +18,7 @@ + + #include <dlfcn.h> + #include <errno.h> ++#include <fcntl.h> /* help musl C */ + #include <pthread.h> + #include <sys/file.h> + #include <sys/stat.h> +-- +2.22.3 +
package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch new file +34 -0
@@ -0,0 +1,34 @@ +From b668022f9b8aecf52109c9e0b7e5847054231361 Mon Sep 17 00:00:00 2001 +From: Zdenek Kabelac <[email protected]> +Date: Fri, 19 Aug 2022 16:15:17 +0200 +Subject: [PATCH] mm: preallocate memory only with glibc + +Use mallinfo() only with glibc. + +Backported from: 8370d117d7ef8a472c95315a3cd085696c90b3be +Signed-off-by: Simon Rowe <[email protected]> +--- + lib/mm/memlock.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c +index 3d1a3927c..efcc6d91f 100644 +--- a/lib/mm/memlock.c ++++ b/lib/mm/memlock.c +@@ -160,7 +160,12 @@ static void _touch_memory(void *mem, size_t size) + + static void _allocate_memory(void) + { +-#ifndef VALGRIND_POOL ++#if defined(__GLIBC__) && !defined(VALGRIND_POOL) ++ /* Memory allocation is currently only tested with glibc ++ * for different C libraries, some other mechanisms might be needed ++ * meanwhile let users use lvm2 code without memory preallocation. ++ * Compilation for VALGRIND tracing also goes without preallocation. ++ */ + void *stack_mem; + struct rlimit limit; + int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks; +-- +2.22.3 +
package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch new file +67 -0
67 lines not on this page · raw message
package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch new file +43 -0
43 lines not on this page · raw message
package/lvm2/Config.in +0 -5
@@ -27,15 +27,10 @@ if BR2_PACKAGE_LVM2 config BR2_PACKAGE_LVM2_STANDARD_INSTALL bool "standard install instead of only dmsetup" default y - # http://lists.busybox.net/pipermail/buildroot/2016-August/170592.html - depends on !BR2_TOOLCHAIN_USES_MUSL help Install the standard suite of lvm2 programs. When this option is not set, only dmsetup is installed. -comment "lvm2 standard install needs a glibc or uClibc toolchain" - depends on BR2_TOOLCHAIN_USES_MUSL - endif comment "lvm2 needs a toolchain w/ threads, dynamic library"
Signature · 6 lines
2.22.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 2/2 package/multipath-tools: enable with musl
Now LVM2 can be built using musl drop the toolchain config restriction.
--- package/multipath-tools/Config.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
package/multipath-tools/Config.in +1 -3
@@ -1,14 +1,12 @@ -comment "multipath-tools needs udev and a uClibc or glibc toolchain w/ threads, dynamic library" +comment "multipath-tools needs udev and a toolchain w/ threads, dynamic library" depends on BR2_USE_MMU depends on BR2_TOOLCHAIN_HAS_SYNC_4 - depends on !BR2_TOOLCHAIN_USES_MUSL depends on BR2_PACKAGE_LIBURCU_ARCH_SUPPORTS depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS || !BR2_PACKAGE_HAS_UDEV config BR2_PACKAGE_MULTIPATH_TOOLS bool "multipath-tools" depends on !BR2_STATIC_LIBS - depends on !BR2_TOOLCHAIN_USES_MUSL depends on BR2_USE_MMU depends on BR2_TOOLCHAIN_HAS_THREADS depends on BR2_TOOLCHAIN_HAS_SYNC_4
Signature · 6 lines
2.22.3 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedRe: [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable with musl
Quoted 7 lines · On Thu, 23 Mar 2023 14:13:27 +0000 Simon Rowe <[email protected]> wrote:
Now LVM2 can be built using musl drop the toolchain config restriction.
Signed-off-by Simon Rowe <[email protected]>--- package/multipath-tools/Config.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Applied to master, thanks.
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 14 lines · On Thu, 23 Mar 2023 14:13:26 +0000 Simon Rowe <[email protected]> wrote:
LVM relies on the glibc-specific behaviour of assigning to the standard streams (stdin etc). As a result the package is currently disabled when using musl.
Apply patches based on those present in gentoo:
https://github.com/gentoo/gentoo/pull/25883 https://github.com/gentoo/gentoo/pull/26024and drop the prohibition on musl in Config.in.
Also, backport a couple of compilation fixes needed build with musl.
Signed-off-by Simon Rowe <[email protected]>
Quoted 11 lines
--- ...sible-better-compilation-with-musl-c.patch | 30 +++++++++ ...m-preallocate-memory-only-with-glibc.patch | 34 ++++++++++ ...e-freopen-to-reopen-standard-streams.patch | 67 +++++++++++++++++++ ...e-freopen-to-reopen-standard-streams.patch | 43 ++++++++++++ package/lvm2/Config.in | 5 -- 5 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 package/lvm2/0001-clang-possible-better-compilation-with-musl-c.patch create mode 100644 package/lvm2/0002-mm-preallocate-memory-only-with-glibc.patch create mode 100644 package/lvm2/0003-cmdline-use-freopen-to-reopen-standard-streams.patch create mode 100644 package/lvm2/0004-log-use-freopen-to-reopen-standard-streams.patch
I've added more references to where the patches were found, and applied. Thanks!
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot