git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #148061 from astro/drbd_upstream

drbd: update, fix, add test

commit542e917e994cd5f96ede5e53a6db1df8f06ceddb authorRyan Mulligan <ryan@ryantm.com> dateSun 5 Dec 2021, 09:10 (5 years ago) parent4722a8e7f4e071
8 files changed+257−73
nixos/modules/services/network-filesystems/drbd.nix+5−7 nixos/tests/all-tests.nix+1 nixos/tests/drbd.nix+87 pkgs/os-specific/linux/drbd/default.nix+106−27 pkgs/os-specific/linux/drbd/fix-glibc-compilation.patch−24 pkgs/os-specific/linux/drbd/pass-force.patch−15 pkgs/os-specific/linux/ocf-resource-agents/default.nix+56 pkgs/top-level/all-packages.nix+2
nixos/modules/services/network-filesystems/drbd.nix+5−7
@@ -47,19 +47,17 @@ let cfg = config.services.drbd; in
4747 options drbd usermode_helper=/run/current-system/sw/bin/drbdadm
4848 '';
4949
50− environment.etc.drbd.conf =
50+ environment.etc."drbd.conf" =
5151 { source = pkgs.writeText "drbd.conf" cfg.config; };
5252
5353 systemd.services.drbd = {
5454 after = [ "systemd-udev.settle.service" "network.target" ];
5555 wants = [ "systemd-udev.settle.service" ];
5656 wantedBy = [ "multi-user.target" ];
57− script = ''
58− ${pkgs.drbd}/sbin/drbdadm up all
59− '';
60− serviceConfig.ExecStop = ''
61− ${pkgs.drbd}/sbin/drbdadm down all
62− '';
57+ serviceConfig = {
58+ ExecStart = "${pkgs.drbd}/sbin/drbdadm up all";
59+ ExecStop = "${pkgs.drbd}/sbin/drbdadm down all";
60+ };
6361 };
6462 };
6563}
nixos/tests/all-tests.nix+1
@@ -111,6 +111,7 @@ in
111111 dokuwiki = handleTest ./dokuwiki.nix {};
112112 domination = handleTest ./domination.nix {};
113113 dovecot = handleTest ./dovecot.nix {};
114+ drbd = handleTest ./drbd.nix {};
114115 ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {};
115116 ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {};
116117 ecryptfs = handleTest ./ecryptfs.nix {};
nixos/tests/drbd.nixnew file+87
@@ -0,0 +1,87 @@
1+import ./make-test-python.nix (
2+ { pkgs, lib, ... }:
3+ let
4+ drbdPort = 7789;
5+
6+ drbdConfig =
7+ { nodes, ... }:
8+ {
9+ virtualisation.emptyDiskImages = [ 1 ];
10+ networking.firewall.allowedTCPPorts = [ drbdPort ];
11+
12+ services.drbd = {
13+ enable = true;
14+ config = ''
15+ global {
16+ usage-count yes;
17+ }
18+
19+ common {
20+ net {
21+ protocol C;
22+ ping-int 1;
23+ }
24+ }
25+
26+ resource r0 {
27+ volume 0 {
28+ device /dev/drbd0;
29+ disk /dev/vdb;
30+ meta-disk internal;
31+ }
32+
33+ on drbd1 {
34+ address ${nodes.drbd1.config.networking.primaryIPAddress}:${toString drbdPort};
35+ }
36+
37+ on drbd2 {
38+ address ${nodes.drbd2.config.networking.primaryIPAddress}:${toString drbdPort};
39+ }
40+ }
41+ '';
42+ };
43+ };
44+ in
45+ {
46+ name = "drbd";
47+ meta = with pkgs.lib.maintainers; {
48+ maintainers = [ ryantm astro ];
49+ };
50+
51+ nodes.drbd1 = drbdConfig;
52+ nodes.drbd2 = drbdConfig;
53+
54+ testScript = { nodes }: ''
55+ drbd1.start()
56+ drbd2.start()
57+
58+ drbd1.wait_for_unit("network.target")
59+ drbd2.wait_for_unit("network.target")
60+
61+ drbd1.succeed(
62+ "drbdadm create-md r0",
63+ "drbdadm up r0",
64+ "drbdadm primary r0 --force",
65+ )
66+
67+ drbd2.succeed("drbdadm create-md r0", "drbdadm up r0")
68+
69+ drbd1.succeed(
70+ "mkfs.ext4 /dev/drbd0",
71+ "mkdir -p /mnt/drbd",
72+ "mount /dev/drbd0 /mnt/drbd",
73+ "touch /mnt/drbd/hello",
74+ "umount /mnt/drbd",
75+ "drbdadm secondary r0",
76+ )
77+ drbd1.sleep(1)
78+
79+ drbd2.succeed(
80+ "drbdadm primary r0",
81+ "mkdir -p /mnt/drbd",
82+ "mount /dev/drbd0 /mnt/drbd",
83+ "ls /mnt/drbd/hello",
84+ )
85+ '';
86+ }
87+)
pkgs/os-specific/linux/drbd/default.nix+106−27
@@ -1,49 +1,128 @@
1−{ lib, stdenv, fetchurl, flex, systemd, perl }:
1+{ lib
2+, stdenv
3+, docbook_xml_dtd_44
4+, docbook_xml_dtd_45
5+, docbook_xsl
6+, asciidoctor
7+, fetchurl
8+, flex
9+, kmod
10+, libxslt
11+, nixosTests
12+, perl
13+, systemd
14+
15+# drbd-utils are compiled twice, once with forOCF = true to extract
16+# its OCF definitions for use in the ocf-resource-agents derivation,
17+# then again with forOCF = false, where the ocf-resource-agents is
18+# provided as the OCF_ROOT.
19+, forOCF ? false
20+, ocf-resource-agents
21+}:
222
323stdenv.mkDerivation rec {
424 pname = "drbd";
5− version = "8.4.4";
25+ version = "9.19.1";
626
727 src = fetchurl {
8− url = "http://oss.linbit.com/drbd/8.4/drbd-${version}.tar.gz";
9− sha256 = "1w4889h1ak7gy9w33kd4fgjlfpgmp6hzfya16p1pkc13bjf22mm0";
28+ url = "https://pkg.linbit.com/downloads/drbd/utils/${pname}-utils-${version}.tar.gz";
29+ sha256 = "1l99kcrb0j85wxxmrdihpx9bk1a4sdi7wlp5m1x5l24k8ck1m5cf";
1030 };
1131
12− patches = [ ./pass-force.patch ./fix-glibc-compilation.patch ];
32+ nativeBuildInputs = [
33+ flex
34+ libxslt
35+ docbook_xsl
36+ asciidoctor
37+ ];
1338
14− nativeBuildInputs = [ flex ];
15− buildInputs = [ perl ];
39+ buildInputs = [
40+ perl
41+ # perlPackages.Po4a used by ja documentation
42+ ];
1643
1744 configureFlags = [
18− "--without-distro"
19− "--without-pacemaker"
45+ "--libdir=${placeholder "out"}/lib"
46+ "--sbindir=${placeholder "out"}/bin"
2047 "--localstatedir=/var"
2148 "--sysconfdir=/etc"
49+ "--without-distro"
2250 ];
2351
24− preConfigure =
25− ''
26− export PATH=${systemd}/sbin:$PATH
27− substituteInPlace user/Makefile.in \
28− --replace /sbin '$(sbindir)'
29− substituteInPlace user/legacy/Makefile.in \
30− --replace '$(DESTDIR)/lib/drbd' '$(DESTDIR)$(LIBDIR)'
31− substituteInPlace user/drbdadm_usage_cnt.c --replace /lib/drbd $out/lib/drbd
32− substituteInPlace scripts/drbd.rules --replace /usr/sbin/drbdadm $out/sbin/drbdadm
33− '';
34−
35− makeFlags = [ "SHELL=${stdenv.shell}" ];
52+ makeFlags = [
53+ "SOURCE_DATE_EPOCH=1"
54+ "WANT_DRBD_REPRODUCIBLE_BUILD=1"
55+ ] ++ lib.optional (!forOCF) "OCF_ROOT=${ocf-resource-agents}/usr/lib/ocf}";
3656
3757 installFlags = [
38− "localstatedir=$(TMPDIR)/var"
39− "sysconfdir=$(out)/etc"
40− "INITDIR=$(out)/etc/init.d"
58+ "prefix="
59+ "DESTDIR=${placeholder "out"}"
60+ "localstatedir=/var"
61+ "DRBD_LIB_DIR=/var/lib"
62+ "INITDIR=/etc/init.d"
63+ "udevrulesdir=/etc/udev/rules.d"
64+ "sysconfdir=/etc"
65+ "sbindir=/bin"
66+ "datadir="
67+ "LIBDIR=/lib/drbd"
68+ "mandir=/share/man"
4169 ];
4270
71+ postPatch = ''
72+ patchShebangs .
73+ substituteInPlace user/v84/drbdadm_usage_cnt.c \
74+ --replace '"/lib/drbd");' \
75+ '"${placeholder "out"}/lib/drbd");'
76+ substituteInPlace user/v9/drbdsetup_linux.c \
77+ --replace 'ret = system("/sbin/modprobe drbd");' \
78+ 'ret = system("${kmod}/bin/modprobe drbd");'
79+ substituteInPlace user/v84/drbdsetup.c \
80+ --replace 'system("/sbin/modprobe drbd")' \
81+ 'system("${kmod}/bin/modprobe drbd")'
82+ substituteInPlace documentation/ra2refentry.xsl \
83+ --replace "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" \
84+ "${docbook_xml_dtd_44}/xml/dtd/docbook/docbookx.dtd"
85+ function patch_docbook45() {
86+ substituteInPlace $1 \
87+ --replace "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" \
88+ "${docbook_xml_dtd_45}/xml/dtd/docbook/docbookx.dtd"
89+ }
90+ patch_docbook45 documentation/v9/drbd.conf.xml.in
91+ patch_docbook45 documentation/v9/drbdsetup.xml.in
92+ patch_docbook45 documentation/v84/drbdsetup.xml
93+ patch_docbook45 documentation/v84/drbd.conf.xml
94+ # The ja documentation is disabled because:
95+ # make[1]: Entering directory '/build/drbd-utils-9.16.0/documentation/ja/v84'
96+ # /nix/store/wyx2nn2pjcn50lc95c6qgsgm606rn0x2-perl5.32.1-po4a-0.62/bin/po4a-translate -f docbook -M utf-8 -L utf-8 -keep 0 -m ../../v84/drbdsetup.xml -p drbdsetup.xml.po -l drbdsetup.xml
97+ # Use of uninitialized value $args[1] in sprintf at /nix/store/wyx2nn2pjcn50lc95c6qgsgm606rn0x2-perl5.32.1-po4a-0.62/lib/perl5/site_perl/Locale/Po4a/Common.pm line 134.
98+ # Invalid po file drbdsetup.xml.po:
99+ substituteInPlace Makefile.in \
100+ --replace 'DOC_DIRS := documentation/v9 documentation/ja/v9' \
101+ 'DOC_DIRS := documentation/v9' \
102+ --replace 'DOC_DIRS += documentation/v84 documentation/ja/v84' \
103+ 'DOC_DIRS += documentation/v84' \
104+ --replace '$(MAKE) -C documentation/ja/v9 doc' \
105+ "" \
106+ --replace '$(MAKE) -C documentation/ja/v84 doc' \
107+ ""
108+ substituteInPlace user/v9/drbdtool_common.c \
109+ --replace 'add_component_to_path("/lib/drbd");' \
110+ 'add_component_to_path("${placeholder "out"}/lib/drbd");'
111+ '';
112+
113+ preConfigure = ''
114+ export PATH=${systemd}/sbin:$PATH
115+ '';
116+
117+ enableParallelBuilding = true;
118+
119+ passthru.tests.drbd = nixosTests.drbd;
120+
43121 meta = with lib; {
44− homepage = "http://www.drbd.org/";
45− description = "Distributed Replicated Block Device, a distributed storage system for Linux";
46− license = licenses.gpl2;
122+ homepage = "https://linbit.com/drbd/";
123+ description = "Distributed Replicated Block Device, a distributed storage system for Linux (userspace utilities)";
124+ license = licenses.gpl2Plus;
47125 platforms = platforms.linux;
126+ maintainers = with maintainers; [ ryantm astro ];
48127 };
49128}
pkgs/os-specific/linux/drbd/fix-glibc-compilation.patchdeleted−24
@@ -1,24 +0,0 @@
1−diff --git a/user/drbdadm_adjust.c b/user/drbdadm_adjust.c
2−index cb23270..3a751ca 100644
3−--- a/user/drbdadm_adjust.c
4−+++ b/user/drbdadm_adjust.c
5−@@ -29,6 +29,7 @@
6− #include <sys/types.h>
7− #include <sys/stat.h>
8− #include <sys/wait.h>
9−+#include <sys/sysmacros.h>
10− #include <unistd.h>
11− #include <fcntl.h>
12−
13−diff --git a/user/legacy/drbdadm_adjust.c b/user/legacy/drbdadm_adjust.c
14−index c79163c..6990ffb 100644
15−--- a/user/legacy/drbdadm_adjust.c
16−+++ b/user/legacy/drbdadm_adjust.c
17−@@ -27,6 +27,7 @@
18− #include <sys/types.h>
19− #include <sys/stat.h>
20− #include <sys/wait.h>
21−+#include <sys/sysmacros.h>
22− #include <unistd.h>
23− #include <fcntl.h>
24−
pkgs/os-specific/linux/drbd/pass-force.patchdeleted−15
@@ -1,15 +0,0 @@
1−Propagate the --force flag in the legacy drbdadm to drbdsetup.
2−Otherwise "drbdadm primary --force" won't work as expected (the kernel
3−will say "State change failed: Need access to UpToDate data").
4−
5−diff -ru -x '*~' drbd-8.4.0-orig/user/legacy/drbdadm_main.c drbd-8.4.0/user/legacy/drbdadm_main.c
6−--- drbd-8.4.0-orig/user/legacy/drbdadm_main.c 2011-07-07 06:55:39.000000000 -0400
7−+++ drbd-8.4.0/user/legacy/drbdadm_main.c 2011-11-02 14:51:04.000000000 -0400
8−@@ -1547,6 +1547,7 @@
9− for (i = 0; i < soi; i++) {
10− argv[NA(argc)] = setup_opts[i];
11− }
12−+ if (force) argv[NA(argc)] = "--force";
13− argv[NA(argc)] = 0;
14−
15− setenv("DRBD_RESOURCE", res->name, 1);
pkgs/os-specific/linux/ocf-resource-agents/default.nixnew file+56
@@ -0,0 +1,56 @@
1+{ stdenv
2+, lib
3+, runCommand
4+, lndir
5+, fetchFromGitHub
6+, autoreconfHook
7+, pkg-config
8+, python3
9+, glib
10+, drbd
11+}:
12+
13+let
14+ drbdForOCF = drbd.override {
15+ forOCF = true;
16+ };
17+
18+ resource-agentsForOCF = stdenv.mkDerivation rec {
19+ pname = "resource-agents";
20+ version = "4.10.0";
21+
22+ src = fetchFromGitHub {
23+ owner = "ClusterLabs";
24+ repo = pname;
25+ rev = "v${version}";
26+ sha256 = "0haryi3yrszdfpqnkfnppxj1yiy6ipah6m80snvayc7v0ss0wnir";
27+ };
28+
29+ nativeBuildInputs = [
30+ autoreconfHook
31+ pkg-config
32+ ];
33+
34+ buildInputs = [
35+ glib
36+ python3
37+ ];
38+
39+ meta = with lib; {
40+ homepage = "https://github.com/ClusterLabs/resource-agents";
41+ description = "Combined repository of OCF agents from the RHCS and Linux-HA projects";
42+ license = licenses.gpl2Plus;
43+ platforms = platforms.linux;
44+ maintainers = with maintainers; [ ryantm astro ];
45+ };
46+ };
47+
48+in
49+
50+# This combines together OCF definitions from other derivations.
51+# https://github.com/ClusterLabs/resource-agents/blob/master/doc/dev-guides/ra-dev-guide.asc
52+runCommand "ocf-resource-agents" {} ''
53+ mkdir -p $out/usr/lib/ocf
54+ ${lndir}/bin/lndir -silent "${resource-agentsForOCF}/lib/ocf/" $out/usr/lib/ocf
55+ ${lndir}/bin/lndir -silent "${drbdForOCF}/usr/lib/ocf/" $out/usr/lib/ocf
56+''
pkgs/top-level/all-packages.nix+2
@@ -22387,6 +22387,8 @@ with pkgs;
2238722387
2238822388 system76-firmware = callPackage ../os-specific/linux/firmware/system76-firmware { };
2238922389
22390+ ocf-resource-agents = callPackage ../os-specific/linux/ocf-resource-agents { };
22391+
2239022392 open-vm-tools = callPackage ../applications/virtualization/open-vm-tools { };
2239122393 open-vm-tools-headless = open-vm-tools.override { withX = false; };
2239222394