3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #148061 from astro/drbd_upstream

drbd: update, fix, add test
This commit is contained in:
Ryan Mulligan 2021-12-05 09:10:22 -08:00 committed by GitHub
commit 542e917e99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 257 additions and 73 deletions

View file

@ -47,19 +47,17 @@ let cfg = config.services.drbd; in
options drbd usermode_helper=/run/current-system/sw/bin/drbdadm
'';
environment.etc.drbd.conf =
environment.etc."drbd.conf" =
{ source = pkgs.writeText "drbd.conf" cfg.config; };
systemd.services.drbd = {
after = [ "systemd-udev.settle.service" "network.target" ];
wants = [ "systemd-udev.settle.service" ];
wantedBy = [ "multi-user.target" ];
script = ''
${pkgs.drbd}/sbin/drbdadm up all
'';
serviceConfig.ExecStop = ''
${pkgs.drbd}/sbin/drbdadm down all
'';
serviceConfig = {
ExecStart = "${pkgs.drbd}/sbin/drbdadm up all";
ExecStop = "${pkgs.drbd}/sbin/drbdadm down all";
};
};
};
}

View file

@ -111,6 +111,7 @@ in
dokuwiki = handleTest ./dokuwiki.nix {};
domination = handleTest ./domination.nix {};
dovecot = handleTest ./dovecot.nix {};
drbd = handleTest ./drbd.nix {};
ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {};
ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {};
ecryptfs = handleTest ./ecryptfs.nix {};

87
nixos/tests/drbd.nix Normal file
View file

@ -0,0 +1,87 @@
import ./make-test-python.nix (
{ pkgs, lib, ... }:
let
drbdPort = 7789;
drbdConfig =
{ nodes, ... }:
{
virtualisation.emptyDiskImages = [ 1 ];
networking.firewall.allowedTCPPorts = [ drbdPort ];
services.drbd = {
enable = true;
config = ''
global {
usage-count yes;
}
common {
net {
protocol C;
ping-int 1;
}
}
resource r0 {
volume 0 {
device /dev/drbd0;
disk /dev/vdb;
meta-disk internal;
}
on drbd1 {
address ${nodes.drbd1.config.networking.primaryIPAddress}:${toString drbdPort};
}
on drbd2 {
address ${nodes.drbd2.config.networking.primaryIPAddress}:${toString drbdPort};
}
}
'';
};
};
in
{
name = "drbd";
meta = with pkgs.lib.maintainers; {
maintainers = [ ryantm astro ];
};
nodes.drbd1 = drbdConfig;
nodes.drbd2 = drbdConfig;
testScript = { nodes }: ''
drbd1.start()
drbd2.start()
drbd1.wait_for_unit("network.target")
drbd2.wait_for_unit("network.target")
drbd1.succeed(
"drbdadm create-md r0",
"drbdadm up r0",
"drbdadm primary r0 --force",
)
drbd2.succeed("drbdadm create-md r0", "drbdadm up r0")
drbd1.succeed(
"mkfs.ext4 /dev/drbd0",
"mkdir -p /mnt/drbd",
"mount /dev/drbd0 /mnt/drbd",
"touch /mnt/drbd/hello",
"umount /mnt/drbd",
"drbdadm secondary r0",
)
drbd1.sleep(1)
drbd2.succeed(
"drbdadm primary r0",
"mkdir -p /mnt/drbd",
"mount /dev/drbd0 /mnt/drbd",
"ls /mnt/drbd/hello",
)
'';
}
)

View file

@ -1,49 +1,128 @@
{ lib, stdenv, fetchurl, flex, systemd, perl }:
{ lib
, stdenv
, docbook_xml_dtd_44
, docbook_xml_dtd_45
, docbook_xsl
, asciidoctor
, fetchurl
, flex
, kmod
, libxslt
, nixosTests
, perl
, systemd
# drbd-utils are compiled twice, once with forOCF = true to extract
# its OCF definitions for use in the ocf-resource-agents derivation,
# then again with forOCF = false, where the ocf-resource-agents is
# provided as the OCF_ROOT.
, forOCF ? false
, ocf-resource-agents
}:
stdenv.mkDerivation rec {
pname = "drbd";
version = "8.4.4";
version = "9.19.1";
src = fetchurl {
url = "http://oss.linbit.com/drbd/8.4/drbd-${version}.tar.gz";
sha256 = "1w4889h1ak7gy9w33kd4fgjlfpgmp6hzfya16p1pkc13bjf22mm0";
url = "https://pkg.linbit.com/downloads/drbd/utils/${pname}-utils-${version}.tar.gz";
sha256 = "1l99kcrb0j85wxxmrdihpx9bk1a4sdi7wlp5m1x5l24k8ck1m5cf";
};
patches = [ ./pass-force.patch ./fix-glibc-compilation.patch ];
nativeBuildInputs = [
flex
libxslt
docbook_xsl
asciidoctor
];
nativeBuildInputs = [ flex ];
buildInputs = [ perl ];
buildInputs = [
perl
# perlPackages.Po4a used by ja documentation
];
configureFlags = [
"--without-distro"
"--without-pacemaker"
"--libdir=${placeholder "out"}/lib"
"--sbindir=${placeholder "out"}/bin"
"--localstatedir=/var"
"--sysconfdir=/etc"
"--without-distro"
];
preConfigure =
''
export PATH=${systemd}/sbin:$PATH
substituteInPlace user/Makefile.in \
--replace /sbin '$(sbindir)'
substituteInPlace user/legacy/Makefile.in \
--replace '$(DESTDIR)/lib/drbd' '$(DESTDIR)$(LIBDIR)'
substituteInPlace user/drbdadm_usage_cnt.c --replace /lib/drbd $out/lib/drbd
substituteInPlace scripts/drbd.rules --replace /usr/sbin/drbdadm $out/sbin/drbdadm
'';
makeFlags = [ "SHELL=${stdenv.shell}" ];
makeFlags = [
"SOURCE_DATE_EPOCH=1"
"WANT_DRBD_REPRODUCIBLE_BUILD=1"
] ++ lib.optional (!forOCF) "OCF_ROOT=${ocf-resource-agents}/usr/lib/ocf}";
installFlags = [
"localstatedir=$(TMPDIR)/var"
"sysconfdir=$(out)/etc"
"INITDIR=$(out)/etc/init.d"
"prefix="
"DESTDIR=${placeholder "out"}"
"localstatedir=/var"
"DRBD_LIB_DIR=/var/lib"
"INITDIR=/etc/init.d"
"udevrulesdir=/etc/udev/rules.d"
"sysconfdir=/etc"
"sbindir=/bin"
"datadir="
"LIBDIR=/lib/drbd"
"mandir=/share/man"
];
postPatch = ''
patchShebangs .
substituteInPlace user/v84/drbdadm_usage_cnt.c \
--replace '"/lib/drbd");' \
'"${placeholder "out"}/lib/drbd");'
substituteInPlace user/v9/drbdsetup_linux.c \
--replace 'ret = system("/sbin/modprobe drbd");' \
'ret = system("${kmod}/bin/modprobe drbd");'
substituteInPlace user/v84/drbdsetup.c \
--replace 'system("/sbin/modprobe drbd")' \
'system("${kmod}/bin/modprobe drbd")'
substituteInPlace documentation/ra2refentry.xsl \
--replace "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" \
"${docbook_xml_dtd_44}/xml/dtd/docbook/docbookx.dtd"
function patch_docbook45() {
substituteInPlace $1 \
--replace "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" \
"${docbook_xml_dtd_45}/xml/dtd/docbook/docbookx.dtd"
}
patch_docbook45 documentation/v9/drbd.conf.xml.in
patch_docbook45 documentation/v9/drbdsetup.xml.in
patch_docbook45 documentation/v84/drbdsetup.xml
patch_docbook45 documentation/v84/drbd.conf.xml
# The ja documentation is disabled because:
# make[1]: Entering directory '/build/drbd-utils-9.16.0/documentation/ja/v84'
# /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
# 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.
# Invalid po file drbdsetup.xml.po:
substituteInPlace Makefile.in \
--replace 'DOC_DIRS := documentation/v9 documentation/ja/v9' \
'DOC_DIRS := documentation/v9' \
--replace 'DOC_DIRS += documentation/v84 documentation/ja/v84' \
'DOC_DIRS += documentation/v84' \
--replace '$(MAKE) -C documentation/ja/v9 doc' \
"" \
--replace '$(MAKE) -C documentation/ja/v84 doc' \
""
substituteInPlace user/v9/drbdtool_common.c \
--replace 'add_component_to_path("/lib/drbd");' \
'add_component_to_path("${placeholder "out"}/lib/drbd");'
'';
preConfigure = ''
export PATH=${systemd}/sbin:$PATH
'';
enableParallelBuilding = true;
passthru.tests.drbd = nixosTests.drbd;
meta = with lib; {
homepage = "http://www.drbd.org/";
description = "Distributed Replicated Block Device, a distributed storage system for Linux";
license = licenses.gpl2;
homepage = "https://linbit.com/drbd/";
description = "Distributed Replicated Block Device, a distributed storage system for Linux (userspace utilities)";
license = licenses.gpl2Plus;
platforms = platforms.linux;
maintainers = with maintainers; [ ryantm astro ];
};
}

View file

@ -1,24 +0,0 @@
diff --git a/user/drbdadm_adjust.c b/user/drbdadm_adjust.c
index cb23270..3a751ca 100644
--- a/user/drbdadm_adjust.c
+++ b/user/drbdadm_adjust.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <sys/sysmacros.h>
#include <unistd.h>
#include <fcntl.h>
diff --git a/user/legacy/drbdadm_adjust.c b/user/legacy/drbdadm_adjust.c
index c79163c..6990ffb 100644
--- a/user/legacy/drbdadm_adjust.c
+++ b/user/legacy/drbdadm_adjust.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <sys/sysmacros.h>
#include <unistd.h>
#include <fcntl.h>

View file

@ -1,15 +0,0 @@
Propagate the --force flag in the legacy drbdadm to drbdsetup.
Otherwise "drbdadm primary --force" won't work as expected (the kernel
will say "State change failed: Need access to UpToDate data").
diff -ru -x '*~' drbd-8.4.0-orig/user/legacy/drbdadm_main.c drbd-8.4.0/user/legacy/drbdadm_main.c
--- drbd-8.4.0-orig/user/legacy/drbdadm_main.c 2011-07-07 06:55:39.000000000 -0400
+++ drbd-8.4.0/user/legacy/drbdadm_main.c 2011-11-02 14:51:04.000000000 -0400
@@ -1547,6 +1547,7 @@
for (i = 0; i < soi; i++) {
argv[NA(argc)] = setup_opts[i];
}
+ if (force) argv[NA(argc)] = "--force";
argv[NA(argc)] = 0;
setenv("DRBD_RESOURCE", res->name, 1);

View file

@ -0,0 +1,56 @@
{ stdenv
, lib
, runCommand
, lndir
, fetchFromGitHub
, autoreconfHook
, pkg-config
, python3
, glib
, drbd
}:
let
drbdForOCF = drbd.override {
forOCF = true;
};
resource-agentsForOCF = stdenv.mkDerivation rec {
pname = "resource-agents";
version = "4.10.0";
src = fetchFromGitHub {
owner = "ClusterLabs";
repo = pname;
rev = "v${version}";
sha256 = "0haryi3yrszdfpqnkfnppxj1yiy6ipah6m80snvayc7v0ss0wnir";
};
nativeBuildInputs = [
autoreconfHook
pkg-config
];
buildInputs = [
glib
python3
];
meta = with lib; {
homepage = "https://github.com/ClusterLabs/resource-agents";
description = "Combined repository of OCF agents from the RHCS and Linux-HA projects";
license = licenses.gpl2Plus;
platforms = platforms.linux;
maintainers = with maintainers; [ ryantm astro ];
};
};
in
# This combines together OCF definitions from other derivations.
# https://github.com/ClusterLabs/resource-agents/blob/master/doc/dev-guides/ra-dev-guide.asc
runCommand "ocf-resource-agents" {} ''
mkdir -p $out/usr/lib/ocf
${lndir}/bin/lndir -silent "${resource-agentsForOCF}/lib/ocf/" $out/usr/lib/ocf
${lndir}/bin/lndir -silent "${drbdForOCF}/usr/lib/ocf/" $out/usr/lib/ocf
''

View file

@ -22387,6 +22387,8 @@ with pkgs;
system76-firmware = callPackage ../os-specific/linux/firmware/system76-firmware { };
ocf-resource-agents = callPackage ../os-specific/linux/ocf-resource-agents { };
open-vm-tools = callPackage ../applications/virtualization/open-vm-tools { };
open-vm-tools-headless = open-vm-tools.override { withX = false; };