Unverified Commit a80e12c2 authored by Bjørn Forsman's avatar Bjørn Forsman Committed by GitHub
Browse files

bcache-tools: 1.0.8 -> 1.1 (#441847)

ofborg for x86_64-darwin has not made progress in 8 days, I'm going to merge.
parents e92111be 86263107
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ in
  ayatana-indicators = runTest ./ayatana-indicators.nix;
  babeld = runTest ./babeld.nix;
  bazarr = runTest ./bazarr.nix;
  bcache = runTestOn [ "x86_64-linux" "aarch64-linux" ] ./bcache.nix;
  bcachefs = runTestOn [ "x86_64-linux" "aarch64-linux" ] ./bcachefs.nix;
  beanstalkd = runTest ./beanstalkd.nix;
  bees = runTest ./bees.nix;

nixos/tests/bcache.nix

0 → 100644
+40 −0
Original line number Diff line number Diff line
{ pkgs, ... }:
{
  name = "bcache";
  meta.maintainers = with pkgs.lib.maintainers; [ pineapplehunter ];

  nodes.machine =
    { pkgs, ... }:
    {
      virtualisation.emptyDiskImages = [ 4096 ];
      networking.hostId = "deadbeef";
      boot.supportedFilesystems = [ "ext4" ];
      environment.systemPackages = [ pkgs.parted ];
    };

  testScript = ''
    machine.succeed("modprobe bcache")
    machine.succeed("bcache version")
    machine.succeed("ls /dev")

    machine.succeed(
        "mkdir /tmp/mnt",
        "udevadm settle",
        "parted --script /dev/vdb mklabel gpt",
        "parted --script /dev/vdb mkpart primary 0% 50% mkpart primary 50% 100%",
        "udevadm settle",
        "bcache make -C /dev/vdb1",
        "bcache make -B /dev/vdb2",
        "udevadm settle",
        "bcache attach /dev/vdb1 /dev/vdb2",
        "bcache set-cachemode /dev/vdb2 writeback",
        "udevadm settle",
        "bcache show",
        "ls /sys/fs/bcache",
        "mkfs.ext4 /dev/bcache0",
        "mount /dev/bcache0 /tmp/mnt",
        "umount /tmp/mnt",
        "udevadm settle",
    )
  '';
}
+0 −42
Original line number Diff line number Diff line
This patch does two things:
1) Drops probe-bcache, so now util-linux detecting functionality is used.
2) Drops bcache-register, moving registering device functionality into rule
   using 'sh'.
This reduces things that need to be present in initrd, replacing them with
already existing functionality and reducing overall initrd size.

diff --git a/69-bcache.rules b/69-bcache.rules
index 9cc7f0d..6a52893 100644
--- a/69-bcache.rules
+++ b/69-bcache.rules
@@ -10,16 +10,11 @@ KERNEL=="fd*|sr*", GOTO="bcache_end"
 # It recognised bcache (util-linux 2.24+)
 ENV{ID_FS_TYPE}=="bcache", GOTO="bcache_backing_found"
 # It recognised something else; bail
-ENV{ID_FS_TYPE}=="?*", GOTO="bcache_backing_end"
-
-# Backing devices: scan, symlink, register
-IMPORT{program}="probe-bcache -o udev $tempnode"
-ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end"
-ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
+GOTO="bcache_backing_end"
 
 LABEL="bcache_backing_found"
 RUN{builtin}+="kmod load bcache"
-RUN+="bcache-register $tempnode"
+RUN+="@shell@ -c 'echo $tempnode > /sys/fs/bcache/register_quiet'"
 LABEL="bcache_backing_end"
 
 # Cached devices: symlink
diff --git a/Makefile b/Makefile
index c824ae3..c5f7309 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,6 @@ 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) -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8/
 	$(INSTALL) -D -m0755 initramfs/hook	$(DESTDIR)/usr/share/initramfs-tools/hooks/bcache
+0 −22
Original line number Diff line number Diff line
diff --git a/bcache.c b/bcache.c
index 8f37445..79806d8 100644
--- 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,
@@ -115,7 +115,7 @@ static const uint64_t crc_table[256] = {
 	0x9AFCE626CE85B507ULL
 };
 
-inline uint64_t crc64(const void *_data, size_t len)
+uint64_t crc64(const void *_data, size_t len)
 {
 	uint64_t crc = 0xFFFFFFFFFFFFFFFFULL;
 	const unsigned char *data = _data;
+31 −26
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchFromGitHub,
  fetchgit,
  pkg-config,
  util-linux,
  bash,
  replaceVars,
  udevCheckHook,
  nixosTests,
}:

stdenv.mkDerivation rec {
  pname = "bcache-tools";
  version = "1.0.8";
  version = "1.1";

  src = fetchFromGitHub {
    owner = "g2p";
    repo = "bcache-tools";
    rev = "v${version}";
    hash = "sha256-6gy0ymecMgEHXbwp/nXHlrUEeDFnmFXWZZPlzP292g4=";
  src = fetchgit {
    url = "https://git.kernel.org/pub/scm/linux/kernel/git/colyli/bcache-tools.git";
    rev = "bcache-tools-${version}";
    hash = "sha256-8BiHC8qxk4otFPyKnvGNk57JSZytEOy51AGertWo2O0=";
  };

  nativeBuildInputs = [
@@ -28,34 +27,36 @@ stdenv.mkDerivation rec {

  doInstallCheck = true;

  # * Remove broken install rules (they ignore $PREFIX) for stuff we don't need
  #   anyway (it's distro specific stuff).
  # * Fixup absolute path to modprobe.
  prePatch = ''
    # * Remove distro specific install rules which are not used in NixOS.
    # * Remove binaries for udev which are not needed on modern systems.
    sed -e "/INSTALL.*initramfs\/hook/d" \
        -e "/INSTALL.*initcpio\/install/d" \
        -e "/INSTALL.*dracut\/module-setup.sh/d" \
        -e "s/pkg-config/$PKG_CONFIG/" \
        -e "/INSTALL.*probe-bcache/d" \
        -i Makefile
    # * Remove probe-bcache which is handled by util-linux
    sed -e "/probe-bcache/d" \
        -i 69-bcache.rules
    # * Replace bcache-register binary with a write to sysfs
    substituteInPlace 69-bcache.rules \
      --replace-fail "bcache-register \$tempnode" "${bash}/bin/sh -c 'echo \$tempnode > /sys/fs/bcache/register'"
  '';

  patches = [
    (replaceVars ./bcache-udev-modern.patch {
      shell = "${bash}/bin/sh";
    })
    ./fix-static.patch
  ];

  makeFlags = [
    "PREFIX=${placeholder "out"}"
    "UDEVLIBDIR=${placeholder "out"}/lib/udev/"
    "PREFIX="
    "DESTDIR=$(out)"
  ];

  preInstall = ''
    mkdir -p "$out/sbin" "$out/lib/udev/rules.d" "$out/share/man/man8"
  '';

  meta = with lib; {
  passthru.tests = {
    inherit (nixosTests) bcache;
  };

  meta = {
    description = "User-space tools required for bcache (Linux block layer cache)";
    longDescription = ''
      Bcache is a Linux kernel block layer cache. It allows one or more fast
@@ -67,9 +68,13 @@ stdenv.mkDerivation rec {
      User documentation is in Documentation/bcache.txt in the Linux kernel
      tree.
    '';
    homepage = "https://bcache.evilpiepirate.org/";
    license = licenses.gpl2Only;
    platforms = platforms.linux;
    maintainers = [ maintainers.bjornfor ];
    homepage = "https://www.kernel.org/doc/html/latest/admin-guide/bcache.html";
    license = lib.licenses.gpl2Only;
    maintainers = with lib.maintainers; [
      bjornfor
      pineapplehunter
    ];
    mainProgram = "bcache-tools";
    platforms = lib.platforms.linux;
  };
}