commit:     31475eb3e28e326553c89753874df3171cdf33ec
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 23 20:52:00 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Thu Jul 23 22:56:47 2020 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=31475eb3

bcache: Switch to UDEV usage

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.scripts                            | 24 ------
 defaults/linuxrc                                   | 10 ---
 defaults/software.sh                               |  7 ++
 gen_cmdline.sh                                     |  4 +-
 gen_initramfs.sh                                   | 28 +++++++
 genkernel                                          |  1 -
 gkbuilds/bcache-tools.gkbuild                      | 27 +++++++
 .../bcache-tools-1.0.8_p20141204-build.patch       | 88 ++++++++++++++++++++++
 .../bcache-tools-1.0.8_p20141204-crc64.patch       | 53 +++++++++++++
 .../bcache-tools-1.0.8_p20141204-modprobe.patch    | 11 +++
 10 files changed, 216 insertions(+), 37 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 5515f49..8e7d109 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1635,30 +1635,6 @@ start_volumes() {
                fi
        fi
 
-       if [ "${USE_BCACHE}" = '1' ]
-       then
-               if [ ! -e /sys/fs/bcache/register_quiet ]
-               then
-                       bad_msg "dobcache invoked but 
'/sys/fs/bcache/register_quiet' does not exist; Skipping bcache initialization 
..."
-               else
-                       good_msg "Registering all block devices in bcache ..."
-
-                       local i=
-                       for i in $(awk '$4 !~ /^(name$|$)/ { print $4 }' 
/proc/partitions)
-                       do
-                               if [ -e "/dev/${i}" ]
-                               then
-                                       # Push all the block devices to 
register_quiet
-                                       # If its bcache, it will bring it up, 
if not, it will simply ignore it.
-                                       log_msg "COMMAND: 'echo \"/dev/${i}\" 
>/sys/fs/bcache/register_quiet'"
-                                       echo "/dev/${i}" 
>/sys/fs/bcache/register_quiet 2>/dev/null
-                               else
-                                       warn_msg "'/dev/${i}' should exist but 
is missing; Ignoring ..."
-                               fi
-                       done
-               fi
-       fi
-
        if [ "${USE_BTRFS}" = '1' ]
        then
                if ! hash btrfs >/dev/null 2>&1

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 4c1b470..e9e97b6 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -147,9 +147,6 @@ do
                                ;;
                        esac
                ;;
-               dobcache)
-                       USE_BCACHE=1
-               ;;
                dobtrfs)
                        USE_BTRFS=1
                ;;
@@ -526,13 +523,6 @@ then
        FIRSTMODS="${FIRSTMODS} crc32_generic"
 fi
 
-if [ "${USE_BCACHE}" = '1' ]
-then
-       # Force loading of bcache module in case module loading would
-       # be skipped because $REAL_ROOT is already present
-       FIRSTMODS="${FIRSTMODS} bcache"
-fi
-
 splash 'init'
 
 cmdline_hwopts

diff --git a/defaults/software.sh b/defaults/software.sh
index a4f15d6..ae7532f 100644
--- a/defaults/software.sh
+++ b/defaults/software.sh
@@ -9,6 +9,13 @@
 # - This file should not override previously defined variables, as their 
values may
 #   originate from user changes to /etc/genkernel.conf .
 
+GKPKG_BCACHE_TOOLS_PN="bcache-tools"
+GKPKG_BCACHE_TOOLS_PV="${GKPKG_BCACHE_TOOLS_PV:-VERSION_BCACHE_TOOLS}"
+GKPKG_BCACHE_TOOLS_DEPS="util-linux eudev"
+GKPKG_BCACHE_TOOLS_SRCTAR="${GKPKG_BCACHE_TOOLS_SRCTAR:-${DISTDIR}/bcache-tools-${GKPKG_BCACHE_TOOLS_PV}.tar.gz}"
+GKPKG_BCACHE_TOOLS_SRCDIR="${GKPKG_BCACHE_TOOLS_SRCDIR:-bcache-tools-399021549984ad27bf4a13ae85e458833fe003d7}"
+GKPKG_BCACHE_TOOLS_BINPKG="${GKPKG_BCACHE_TOOLS_BINPKG:-%%CACHE%%/bcache-tools-${GKPKG_BCACHE_TOOLS_PV}-%%ARCH%%.tar.xz}"
+
 GKPKG_BOOST_PN="boost"
 GKPKG_BOOST_PV="${GKPKG_BOOST_PV:-VERSION_BOOST}"
 GKPKG_BOOST_DEPS="boost-build"

diff --git a/gen_cmdline.sh b/gen_cmdline.sh
index 5e667bd..f502350 100755
--- a/gen_cmdline.sh
+++ b/gen_cmdline.sh
@@ -35,8 +35,6 @@ longusage() {
   echo "       --no-xconfig            Don't run xconfig after oldconfig"
   echo "       --save-config           Save the configuration to /etc/kernels"
   echo "       --no-save-config        Don't save the configuration to 
/etc/kernels"
-  echo "       --bcache                Enable block layer cache (bcache) 
support in kernel"
-  echo "       --no-bcache             Don't enable block layer cache (bcache) 
support in kernel"
   echo "       --hyperv                Enable Microsoft Hyper-V kernel options 
in kernel"
   echo "       --no-hyperv             Don't enable Microsoft Hyper-V kernel 
options in kernel"
   echo "       --microcode=(all|amd|intel)"
@@ -117,6 +115,8 @@ longusage() {
   echo "       --do-keymap-auto        Forces keymap selection at boot"
   echo "       --keymap                Enables keymap selection support"
   echo "       --no-keymap             Disables keymap selection support"
+  echo "       --bcache                Include block layer cache (bcache) 
support"
+  echo "       --no-bcache             Exclude block layer cache (bcache) 
support"
   echo "       --lvm                   Include LVM support"
   echo "       --no-lvm                Exclude LVM support"
   echo "       --mdadm                 Include MDADM/MDMON support"

diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index 0669f74..af0ff44 100755
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -398,6 +398,7 @@ append_base_layout() {
        isTrue "${MICROCODE_INITRAMFS}" && build_parameters+=( 
--microcode-initramfs ) || build_parameters+=( --no-microcode-initramfs )
        isTrue "${RAMDISKMODULES}" && build_parameters+=( --ramdisk-modules ) 
|| build_parameters+=( --no-ramdisk-modules )
        isTrue "${BUSYBOX}" && build_parameters+=( --busybox ) || 
build_parameters+=( --no-busybox )
+       isTrue "${BCACHE}" && build_parameters+=( --bcache ) || 
build_parameters+=( --no-bcache )
        isTrue "${B2SUM}" && build_parameters+=( --b2sum ) || 
build_parameters+=( --no-b2sum )
        isTrue "${DISKLABEL}" && build_parameters+=( --disklabel ) || 
build_parameters+=( --no-disklabel )
        isTrue "${BTRFS}" && build_parameters+=( --btrfs ) || 
build_parameters+=( --no-btrfs )
@@ -608,6 +609,32 @@ append_b2sum() {
        fi
 }
 
+append_bcache() {
+       local PN="bcache-tools"
+       local TDIR="${TEMP}/initramfs-bcache-temp"
+       if [ -d "${TDIR}" ]
+       then
+               rm -r "${TDIR}" || gen_die "Failed to clean out existing 
'${TDIR}'!"
+       fi
+
+       populate_binpkg ${PN}
+
+       mkdir -p "${TDIR}" || gen_die "Failed to create '${TDIR}'!"
+
+       unpack "$(get_gkpkg_binpkg "${PN}")" "${TDIR}"
+
+       cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
+       log_future_cpio_content
+       find . -print0 | "${CPIO_COMMAND}" ${CPIO_ARGS} --append -F 
"${CPIO_ARCHIVE}" \
+               || gen_die "Failed to append bcache to cpio!"
+
+       cd "${TEMP}" || die "Failed to chdir to '${TEMP}'!"
+       if isTrue "${CLEANUP}"
+       then
+               rm -rf "${TDIR}"
+       fi
+}
+
 append_blkid() {
        local PN="util-linux"
        local TDIR="${TEMP}/initramfs-blkid-temp"
@@ -1869,6 +1896,7 @@ create_initramfs() {
        append_data 'iscsi' "${ISCSI}"
        append_data 'luks' "${LUKS}"
        append_data 'lvm' "${LVM}"
+       append_data 'bcache' "${BCACHE}"
        append_data 'mdadm' "${MDADM}"
        append_data 'modprobed'
        append_data 'multipath' "${MULTIPATH}"

diff --git a/genkernel b/genkernel
index 434d6be..1a12bbb 100755
--- a/genkernel
+++ b/genkernel
@@ -507,7 +507,6 @@ then
        print_warning 1 "${BOLD}WARNING... WARNING... WARNING...${NORMAL}"
        print_warning 1 'Additional kernel parameters that *may* be required to 
boot properly:'
        isTrue "${SPLASH}"    && print_warning 1 "- Add \"vga=791 
splash=silent,theme:${SPLASH_THEME} console=tty1 quiet\" if you use a splash 
framebuffer ]"
-       isTrue "${BCACHE}"    && print_warning 1 '- Add "dobcache" for bcache 
support'
        isTrue "${BTRFS}"     && print_warning 1 '- Add "dobtrfs" for Btrfs 
device scanning support'
        isTrue "${MULTIPATH}" && print_warning 1 '- Add "domultipath" for 
multipath support'
        isTrue "${ISCSI}"     && print_warning 1 '- For iSCSI support, add at 
least:'

diff --git a/gkbuilds/bcache-tools.gkbuild b/gkbuilds/bcache-tools.gkbuild
new file mode 100644
index 0000000..f34828b
--- /dev/null
+++ b/gkbuilds/bcache-tools.gkbuild
@@ -0,0 +1,27 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+src_configure() {
+       append-ldflags -static
+}
+
+src_compile() {
+       PKG_CONFIG="$(tc-getPKG_CONFIG) -static" \
+       gkmake V=1
+}
+
+src_install() {
+       gkmake V=1 UDEVLIBDIR="$(get_udevdir)" DESTDIR="${D}" install
+
+       rm -rf \
+               "${D}"/lib \
+               "${D}"/usr/lib/initcpio \
+               "${D}"/usr/sbin \
+               "${D}"/usr/share
+
+       "${STRIP}" --strip-all "${D}"/usr/lib/udev/bcache-register \
+               || die "Failed to strip '${D}/usr/lib/udev/bcache-register'!"
+
+       "${STRIP}" --strip-all "${D}"/usr/lib/udev/probe-bcache \
+               || die "Failed to strip '${D}/usr/lib/udev/probe-bcache'!"
+}

diff --git 
a/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-build.patch 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-build.patch
new file mode 100644
index 0000000..6f6d4ca
--- /dev/null
+++ 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-build.patch
@@ -0,0 +1,88 @@
+--- a/Makefile
++++ b/Makefile
+@@ -1,32 +1,63 @@
++CC ?= gcc
++PREFIX = /usr
++UDEVLIBDIR = /lib/udev
++DRACUTLIBDIR = /lib/dracut
++INSTALL ?= install
++CFLAGS ?= -O2 -Wall -g
++PKG_CONFIG ?= pkg-config
+ 
+-PREFIX=/usr
+-UDEVLIBDIR=/lib/udev
+-DRACUTLIBDIR=/lib/dracut
+-INSTALL=install
+-CFLAGS+=-O2 -Wall -g
++BCACHE_TEST_LIBS = $(shell $(PKG_CONFIG) --libs openssl) -lm
++
++MAKE_BCACHE_CFLAGS = $(shell $(PKG_CONFIG) --cflags uuid blkid)
++MAKE_BCACHE_LIBS = $(shell $(PKG_CONFIG) --libs uuid blkid)
++
++PROBE_BCACHE_CFLAGS = $(shell $(PKG_CONFIG) --cflags uuid blkid)
++PROBE_BCACHE_LIBS = $(shell $(PKG_CONFIG) --libs uuid blkid)
++
++BCACHE_SUPER_SHOW_CFLAGS = -std=gnu99 $(shell $(PKG_CONFIG) --cflags uuid)
++BCACHE_SUPER_SHOW_LIBS = $(shell $(PKG_CONFIG) --libs uuid)
+ 
+ all: make-bcache probe-bcache bcache-super-show bcache-register
+ 
+ install: make-bcache probe-bcache bcache-super-show
+-      $(INSTALL) -m0755 make-bcache bcache-super-show 
$(DESTDIR)${PREFIX}/sbin/
+-      $(INSTALL) -m0755 probe-bcache bcache-register          
$(DESTDIR)$(UDEVLIBDIR)/
+-      $(INSTALL) -m0644 69-bcache.rules       $(DESTDIR)$(UDEVLIBDIR)/rules.d/
++      $(INSTALL) -m0755 -d $(DESTDIR)${PREFIX}/sbin
++      $(INSTALL) -D -m0755 make-bcache bcache-super-show 
$(DESTDIR)${PREFIX}/sbin/
++      $(INSTALL) -m0755 -d $(DESTDIR)$(UDEVLIBDIR)/rules.d
++      $(INSTALL) -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/
++      $(INSTALL) -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/
++      $(INSTALL) -m0755 -d $(DESTDIR)${PREFIX}/share/man/man8
+       $(INSTALL) -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/
+-      $(INSTALL) -D -m0755 initramfs/hook     
$(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
+-      $(INSTALL) -D -m0755 initcpio/install   
$(DESTDIR)/usr/lib/initcpio/install/bcache
++      $(INSTALL) -D -m0755 initramfs/hook 
$(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
++      $(INSTALL) -D -m0755 initcpio/install 
$(DESTDIR)/usr/lib/initcpio/install/bcache
+       $(INSTALL) -D -m0755 dracut/module-setup.sh 
$(DESTDIR)$(DRACUTLIBDIR)/modules.d/90bcache/module-setup.sh
+ #     $(INSTALL) -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/
+ 
+ clean:
+-      $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test -- *.o
+-
+-bcache-test: LDLIBS += `pkg-config --libs openssl` -lm
+-make-bcache: LDLIBS += `pkg-config --libs uuid blkid`
+-make-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
+-make-bcache: bcache.o
+-probe-bcache: LDLIBS += `pkg-config --libs uuid blkid`
+-probe-bcache: CFLAGS += `pkg-config --cflags uuid blkid`
+-bcache-super-show: LDLIBS += `pkg-config --libs uuid`
+-bcache-super-show: CFLAGS += -std=gnu99
+-bcache-super-show: bcache.o
++      $(RM) -f make-bcache probe-bcache bcache-register bcache-super-show 
bcache-test -- *.o
++
++make-bcache: bcache.o make-bcache.o
++      $(CC) -o $@ $^ $(LDFLAGS) $(MAKE_BCACHE_LIBS)
++
++bcache.o: bcache.c bcache.h
++      $(CC) -c $(CFLAGS) $< -o $@
++
++make-bcache.o: make-bcache.c
++      $(CC) -c $(CFLAGS) $(MAKE_BCACHE_CFLAGS) $< -o $@
++
++probe-bcache: probe-bcache.o
++      $(CC) -o $@ $^ $(LDFLAGS) $(PROBE_BCACHE_LIBS)
++
++probe-bcache.o: probe-bcache.c
++      $(CC) -c $(CFLAGS) $(PROBE_BCACHE_CFLAGS) $< -o $@
++
++bcache-super-show: bcache.o bcache-super-show.o
++      $(CC) -o $@ $^ $(LDFLAGS) $(BCACHE_SUPER_SHOW_LIBS)
++
++bcache-super-show.o: bcache-super-show.c
++      $(CC) -c $(CFLAGS) $(BCACHE_SUPER_SHOW_CFLAGS) $< -o $@
++
+ bcache-register: bcache-register.o
++      $(CC) -o $@ $^ $(LDFLAGS) $(BCACHE_SUPER_SHOW_LIBS)
++
++bcache-register.o: bcache-register.c
++      $(CC) -c $(CFLAGS) $< -o $@
+ 

diff --git 
a/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-crc64.patch 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-crc64.patch
new file mode 100644
index 0000000..cc4e0c5
--- /dev/null
+++ 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-crc64.patch
@@ -0,0 +1,53 @@
+--- a/bcache.c
++++ b/bcache.c
+@@ -26,7 +26,7 @@
+  * x^7 + x^4 + x + 1
+ */
+ 
+-static const uint64_t crc_table[256] = {
++const uint64_t crc_table[256] = {
+       0x0000000000000000ULL, 0x42F0E1EBA9EA3693ULL, 0x85E1C3D753D46D26ULL,
+       0xC711223CFA3E5BB5ULL, 0x493366450E42ECDFULL, 0x0BC387AEA7A8DA4CULL,
+       0xCCD2A5925D9681F9ULL, 0x8E224479F47CB76AULL, 0x9266CC8A1C85D9BEULL,
+@@ -114,16 +114,3 @@ static const uint64_t crc_table[256] = {
+       0x5DEDC41A34BBEEB2ULL, 0x1F1D25F19D51D821ULL, 0xD80C07CD676F8394ULL,
+       0x9AFCE626CE85B507ULL
+ };
+-
+-inline uint64_t crc64(const void *_data, size_t len)
+-{
+-      uint64_t crc = 0xFFFFFFFFFFFFFFFFULL;
+-      const unsigned char *data = _data;
+-
+-      while (len--) {
+-              int i = ((int) (crc >> 56) ^ *data++) & 0xFF;
+-              crc = crc_table[i] ^ (crc << 8);
+-      }
+-
+-      return crc ^ 0xFFFFFFFFFFFFFFFFULL;
+-}
+--- a/bcache.h
++++ b/bcache.h
+@@ -115,7 +115,20 @@ BITMASK(BDEV_STATE,               struct cache_sb, flags, 
61, 2);
+ #define BDEV_STATE_DIRTY      2U
+ #define BDEV_STATE_STALE      3U
+ 
+-uint64_t crc64(const void *_data, size_t len);
++extern const uint64_t crc_table[];
++
++static inline uint64_t crc64(const void *_data, size_t len)
++{
++        uint64_t crc = 0xFFFFFFFFFFFFFFFFULL;
++        const unsigned char *data = _data;
++
++        while (len--) {
++                int i = ((int) (crc >> 56) ^ *data++) & 0xFF;
++                crc = crc_table[i] ^ (crc << 8);
++        }
++
++        return crc ^ 0xFFFFFFFFFFFFFFFFULL;
++}
+ 
+ #define node(i, j)            ((void *) ((i)->d + (j)))
+ #define end(i)                        node(i, (i)->keys)
+ 

diff --git 
a/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-modprobe.patch
 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-modprobe.patch
new file mode 100644
index 0000000..aedfe29
--- /dev/null
+++ 
b/patches/bcache-tools/1.0.8_p20141204/bcache-tools-1.0.8_p20141204-modprobe.patch
@@ -0,0 +1,11 @@
+--- a/69-bcache.rules
++++ b/69-bcache.rules
+@@ -18,7 +18,7 @@ ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end"
+ ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
+ 
+ LABEL="bcache_backing_found"
+-RUN{builtin}+="kmod load bcache"
++RUN+="/sbin/modprobe bcache"
+ RUN+="bcache-register $tempnode"
+ LABEL="bcache_backing_end"
+ 

Reply via email to