# [solved] Kernel 5 drbd-utils drbdadm Invalid argument

## olli.bo

Hi,

after update from Kernel 4.19 to 5.4 I'm getting "Invalid argument" while opening drbd device:

```
$ sudo drbdadm -v up r0

drbdsetup new-resource r0

r0: Invalid argument
```

Same as described here:

https://bugs.launchpad.net/ubuntu/+source/drbd-utils/+bug/1866458

https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg64900.html

Seems drbd-utils have to be fixed for Kernel 5.4.

Is the fix in progress?

thx

olliLast edited by olli.bo on Sat Apr 25, 2020 8:51 pm; edited 1 time in total

----------

## olli.bo

Created bug:

https://bugs.gentoo.org/716810

Hoping for a fix.

----------

## olli.bo

In the bug Jonas Stein suggests to apply the patch manually and get help to do this here in there forum.

I have no idea how to do this. Can anybody help?

----------

## fedeliallalinea

You can apply patch using /etc/portage/patches

----------

## electronvolt

Not sure whether you ever had any success but I finally manage to create a solution to get drbd-utils working on a Kernel 5.4.

I initially tried to use /etc/portage/patches but never managed to get it to work, so added it to my local portage overlay and edited the drbd-utils ebuild to add the necessary patch. If you haven't currently got a local portage overlay you will need to create it as follows:-

edit your make.conf file (this is either /etc/portage/make.conf or /etc/make.conf) and add the following line, right at the bottom of the file is fine:-

so either

```
nano /etc/make.conf
```

or

```
nano /etc/portage/make.conf
```

and add:-

```
PORTDIR_OVERLAY="/usr/local/portage"
```

next create the necessary directories:-

```
mkdir /usr/local/portage

mkdir /usr/local/portage/sys-cluster

mkdir /usr/local/portage/sys-cluster/drbd-utils
```

copy over the necessary files from the main portage tree:-

```
cp -a /usr/portage/sys-cluster/drbd-utils/drbd-utils-8.9.6-r1.ebuild /usr/local/portage/sys-cluster/drbd-utils/

cp -a /usr/portage/sys-cluster/drbd-utils/files /usr/local/portage/sys-cluster/drbd-utils/
```

edit the ebuild and add the necessary line for the patch as indicated :-

```
cd /usr/local/portage/sys-cluster/drbd-utils

nano drbd-utils-8.9.6-r1.ebuild

```

```
    epatch "${FILESDIR}/${P}"-sysmacros.patch

    epatch "${FILESDIR}"/NLA_F_NESTED.patch    <-----this is the extra line, added towards the bottom of the src_prepare section

    autoreconf

```

Next create the patch file, this needs to be in the files directory and called NLA_F_NESTED.patch

```
nano files/NLA_F_NESTED.patch 
```

add the following and save the file:-

```
--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

+++ drbd-utils-8.9.6/user/shared/libgenl.h

@@ -843,7 +843,7 @@

 {

    struct nlattr *start = (struct nlattr *)msg->tail;

 

-   if (nla_put(msg, attrtype, 0, NULL) < 0)

+   if (nla_put(msg, attrtype | NLA_F_NESTED, 0, NULL) < 0)

       return NULL;

 

    return start;

```

next you need to generate the manifest for the new ebuild and files:-

you may need to emerge repoman first!

```
repoman manifest
```

next emerge drbd-utils once again and it should build from the local portage overlay and work with a 5.4 kernel!!

HTH

----------

## olli.bo

Hi electronvolt,

thank you so much for helping.

Did the steps you reported.

Now I'm getting an error while emerging:

```
xgabosh /usr/local/portage/sys-cluster/drbd-utils # emerge drbd-utils

Calculating dependencies... done!

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) sys-cluster/drbd-utils-8.9.6-r1::x-portage

 * drbd-utils-8.9.6.tar.gz BLAKE2B SHA512 size ;-) ...                                                           [ ok ]

>>> Unpacking source...

>>> Unpacking drbd-utils-8.9.6.tar.gz to /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work

>>> Source unpacked in /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work

>>> Preparing source in /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6 ...

 * Applying run-lock.patch ...                                                                                   [ ok ]

 * Applying drbd-utils-8.9.6-sysmacros.patch ...                                                                 [ ok ]

 * Applying NLA_F_NESTED.patch ...

 * Failed Patch: NLA_F_NESTED.patch !

 *  ( /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch )

 * 

 * Include in your bugreport the contents of:

 * 

 *   /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/NLA_F_NESTED.patch.out

 * ERROR: sys-cluster/drbd-utils-8.9.6-r1::x-portage failed (prepare phase):

 *   Failed Patch: NLA_F_NESTED.patch!

 * 

 * Call stack:

 *     ebuild.sh, line  125:  Called src_prepare

 *   environment, line 2084:  Called epatch '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

 *   environment, line  717:  Called die

 * The specific snippet of code:

 *               die "Failed Patch: ${patchname}!";

 * 

 * If you need support, post the output of `emerge --info '=sys-cluster/drbd-utils-8.9.6-r1::x-portage'`,

 * the complete build log and the output of `emerge -pqv '=sys-cluster/drbd-utils-8.9.6-r1::x-portage'`.

 * The complete build log is located at '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/build.log'.

 * The ebuild environment file is located at '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/environment'.

 * Working directory: '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6'

 * S: '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6'

>>> Failed to emerge sys-cluster/drbd-utils-8.9.6-r1, Log file:

>>>  '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/build.log'

 * Messages for package sys-cluster/drbd-utils-8.9.6-r1:

 * Failed Patch: NLA_F_NESTED.patch !

 *  ( /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch )

 * 

 * Include in your bugreport the contents of:

 * 

 *   /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/NLA_F_NESTED.patch.out

 * ERROR: sys-cluster/drbd-utils-8.9.6-r1::x-portage failed (prepare phase):

 *   Failed Patch: NLA_F_NESTED.patch!

 * 

 * Call stack:

 *     ebuild.sh, line  125:  Called src_prepare

 *   environment, line 2084:  Called epatch '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

 *   environment, line  717:  Called die

 * The specific snippet of code:

 *               die "Failed Patch: ${patchname}!";

 * 

 * If you need support, post the output of `emerge --info '=sys-cluster/drbd-utils-8.9.6-r1::x-portage'`,

 * the complete build log and the output of `emerge -pqv '=sys-cluster/drbd-utils-8.9.6-r1::x-portage'`.

 * The complete build log is located at '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/build.log'.

 * The ebuild environment file is located at '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/environment'.

 * Working directory: '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6'

 * S: '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6'
```

Here some additional infos:

```
xgabosh /usr/local/portage/sys-cluster/drbd-utils # find . -ls

   924408      4 drwxr-xr-x   3 root     root         4096 Apr 24 10:17 .

   925071      4 -rw-r--r--   1 root     root         2520 Apr 24 10:14 ./drbd-utils-8.9.6-r1.ebuild

   925056      4 -rw-r--r--   1 root     root         1832 Apr 24 10:17 ./Manifest

   924505      4 drwxr-xr-x   2 root     root         4096 Apr 24 10:18 ./files

   925055      4 -rw-r--r--   1 root     root          564 Sep 17  2015 ./files/run-lock.patch

   925067      4 -rw-r--r--   1 root     root          321 Apr 24 10:18 ./files/NLA_F_NESTED.patch

   924561      4 -rw-r--r--   1 root     root         1749 Mai  4  2018 ./files/drbd-utils-8.9.6-sysmacros.patch

   924513      4 -rw-r--r--   1 root     root         3073 Feb 28  2017 ./files/drbd-utils-8.0.rc

xgabosh /usr/local/portage/sys-cluster/drbd-utils # cat ./files/NLA_F_NESTED.patch

--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

+++ drbd-utils-8.9.6/user/shared/libgenl.h

@@ -843,7 +843,7 @@

 {

    struct nlattr *start = (struct nlattr *)msg->tail;

 

-   if (nla_put(msg, attrtype, 0, NULL) < 0)

+   if (nla_put(msg, attrtype | NLA_F_NESTED, 0, NULL) < 0)

       return NULL;

 

    return start;

    

xgabosh /usr/local/portage/sys-cluster/drbd-utils # cat ./drbd-utils-8.9.6-r1.ebuild

# Copyright 1999-2018 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

EAPI=5

inherit bash-completion-r1 eutils multilib udev versionator

LICENSE="GPL-2"

DESCRIPTION="mirror/replicate block-devices across a network-connection"

SRC_URI="http://oss.linbit.com/drbd/${P/_/}.tar.gz"

HOMEPAGE="http://www.drbd.org"

KEYWORDS="amd64 x86"

IUSE="heartbeat pacemaker +udev xen"

SLOT="0"

DEPEND="heartbeat? ( sys-cluster/heartbeat )

   pacemaker? ( sys-cluster/pacemaker )

   udev? ( virtual/udev )

   !!sys-cluster/drbd"

RDEPEND="${DEPEND}"

S="${WORKDIR}/${P/_/}"

src_prepare() {

   # respect LDFLAGS, #453442

   sed -e "s/\$(CC) -o/\$(CC) \$(LDFLAGS) -o/" \

      -e "/\$(DESTDIR)\$(localstatedir)\/lock/d" \

      -i user/*/Makefile.in || die

   # respect multilib

   sed -i -e "s:/lib/:/$(get_libdir)/:g" \

      Makefile.in scripts/{Makefile.in,global_common.conf,drbd.conf.example} || die

   sed -e "s:@prefix@/lib:@prefix@/$(get_libdir):" \

      -e "s:(DESTDIR)/lib:(DESTDIR)/$(get_libdir):" \

      -i user/*/Makefile.in || die

   # correct install paths (really correct this time)

   sed -i -e "s:\$(sysconfdir)/bash_completion.d:$(get_bashcompdir):" \

      scripts/Makefile.in || die

   # don't participate in user survey bug 360483

   sed -i -e '/usage-count/ s/yes/no/' scripts/global_common.conf || die

   sed -i -e "s:\$(sysconfdir)/udev:$(get_udevdir):" scripts/Makefile.in || die

   epatch "${FILESDIR}"/run-lock.patch

   # bug 616758

   epatch "${FILESDIR}/${P}"-sysmacros.patch

   epatch "${FILESDIR}"/NLA_F_NESTED.patch

   autoreconf

}

src_configure() {

   econf \

      --localstatedir=/var \

      --without-rgmanager \

      $(use_with udev) \

      $(use_with xen) \

      $(use_with pacemaker) \

      $(use_with heartbeat) \

      --with-bashcompletion \

      --with-distro=gentoo

}

src_compile() {

   # only compile the tools

   emake OPTFLAGS="${CFLAGS}" tools

}

src_install() {

   # only install the tools

   emake DESTDIR="${D}" install-tools install-doc

   dodoc README ChangeLog

   # install our own init script

   newinitd "${FILESDIR}"/${PN}-8.0.rc ${PN/-utils/}

   dodoc scripts/drbd.conf.example

   dosym /usr/sbin/drbdadm /sbin/drbdadm

}

pkg_postinst() {

   einfo

   einfo "Please copy and gunzip the configuration file:"

   einfo "from /usr/share/doc/${PF}/${PN/-utils/}.conf.example.bz2 to /etc/${PN/-utils/}.conf"

   einfo "and edit it to your needs. Helpful commands:"

   einfo "man 5 drbd.conf"

   einfo "man 8 drbdsetup"

   einfo "man 8 drbdadm"

   einfo "man 8 drbddisk"

   einfo "man 8 drbdmeta"

   einfo

   elog "Remember to enable drbd support in kernel."

}

xgabosh /usr/local/portage/sys-cluster/drbd-utils # grep OVERLAY /etc/portage/make.conf

PORTDIR_OVERLAY="/usr/local/portage/"
```

```
xgabosh /usr/local/portage/sys-cluster/drbd-utils # cat /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/temp/NLA_F_NESTED.patch.out

***** NLA_F_NESTED.patch *****

PWD: /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6

PATCH TOOL: patch -> /usr/bin/patch

VERSION INFO:

GNU patch 2.7.6

Copyright (C) 2003, 2009-2012 Free Software Foundation, Inc.

Copyright (C) 1988 Larry Wall

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Written by Larry Wall and Paul Eggert

==============================

PATCH COMMAND:  patch -p0 -g0 -E --no-backup-if-mismatch  --dry-run -f < '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

==============================

can't find file to patch at input line 3

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

|+++ drbd-utils-8.9.6/user/shared/libgenl.h

--------------------------

No file to patch.  Skipping patch.

1 out of 1 hunk ignored

patch program exited with status 1

==============================

PATCH COMMAND:  patch -p1 -g0 -E --no-backup-if-mismatch  --dry-run -f < '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

==============================

checking file user/shared/libgenl.h

Hunk #1 FAILED at 843.

1 out of 1 hunk FAILED

patch program exited with status 1

==============================

PATCH COMMAND:  patch -p2 -g0 -E --no-backup-if-mismatch  --dry-run -f < '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

==============================

can't find file to patch at input line 3

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

|+++ drbd-utils-8.9.6/user/shared/libgenl.h

--------------------------

No file to patch.  Skipping patch.

1 out of 1 hunk ignored

patch program exited with status 1

==============================

PATCH COMMAND:  patch -p3 -g0 -E --no-backup-if-mismatch  --dry-run -f < '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

==============================

can't find file to patch at input line 3

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

|+++ drbd-utils-8.9.6/user/shared/libgenl.h

--------------------------

No file to patch.  Skipping patch.

1 out of 1 hunk ignored

patch program exited with status 1

==============================

PATCH COMMAND:  patch -p4 -g0 -E --no-backup-if-mismatch  --dry-run -f < '/var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/files/NLA_F_NESTED.patch'

==============================

can't find file to patch at input line 3

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

|+++ drbd-utils-8.9.6/user/shared/libgenl.h

--------------------------

No file to patch.  Skipping patch.

1 out of 1 hunk ignored

patch program exited with status 1
```

Any idea whats going wrong?

----------

## olli.bo

Hi fedeliallalinea,

thank you for the patch link.

Tried to place patch-file from electronvolt to /etc/portage/patches/sys-cluster/drbd-utils-8.9.6-r1/NLA_F_NESTED.patch (without OVERLAY) but it seems to be ignored while emerging:

```
# emerge drbd-utils

Calculating dependencies... done!

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) sys-cluster/drbd-utils-8.9.6-r1::gentoo

 * drbd-utils-8.9.6.tar.gz BLAKE2B SHA512 size ;-) ...                                                           [ ok ]

>>> Unpacking source...

>>> Unpacking drbd-utils-8.9.6.tar.gz to /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work

>>> Source unpacked in /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work

>>> Preparing source in /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6 ...

 * Applying run-lock.patch ...                                                                                   [ ok ]

 * Applying drbd-utils-8.9.6-sysmacros.patch ...                                                                 [ ok ]

>>> Source prepared.

>>> Configuring source in /var/tmp/portage/sys-cluster/drbd-utils-8.9.6-r1/work/drbd-utils-8.9.6 ...

./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --libdir=/usr/lib64 --localstatedir=/var --without-rgmanager --with-udev --without-xen --without-pacemaker --without-heartbeat --with-bashcompletion --with-distro=gentoo

checking for x86_64-pc-linux-gnu-pkg-config... /usr/bin/x86_64-pc-linux-gnu-pkg-config

checking pkg-config is at least version 0.9.0... yes

Package systemd was not found in the pkg-config search path.

Perhaps you should add the directory containing `systemd.pc'

to the PKG_CONFIG_PATH environment variable

No package 'systemd' found

configure: Could not detect systemd unit directory

Using systemd unit directory: 

Using udev rules directory: /lib/udev

checking for x86_64-pc-linux-gnu-gcc... x86_64-pc-linux-gnu-gcc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

[...]
```

```
# cat /etc/portage/patches/sys-cluster/drbd-utils-8.9.6-r1/NLA_F_NESTED.patch 

--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

+++ drbd-utils-8.9.6/user/shared/libgenl.h

@@ -843,7 +843,7 @@

 {

    struct nlattr *start = (struct nlattr *)msg->tail;

 

-   if (nla_put(msg, attrtype, 0, NULL) < 0)

+   if (nla_put(msg, attrtype | NLA_F_NESTED, 0, NULL) < 0)

       return NULL;

 

    return start;

```

Any idea whats wrong?

----------

## electronvolt

Hi olli.bo

the problem is that the forum bbcode does not respect formatting and removes <tabs> Until I find a more elegant solution you will have to edit the patch file and correctly format it

```
cd /usr/local/portage/sys-cluster/drbd-utils

nano files/NLA_F_NESTED.patch
```

add the spaces/tabs exactly as indicated

```

--- drbd-utils-8.9.6.orig/user/shared/libgenl.h

+++ drbd-utils-8.9.6/user/shared/libgenl.h

@@ -843,7 +843,7 @@

 {

<space><tab>struct nlattr *start = (struct nlattr *)msg->tail;

<space>

-<tab>if (nla_put(msg, attrtype, 0, NULL) < 0)

+<tab>if (nla_put(msg, attrtype | NLA_F_NESTED, 0, NULL) < 0)

<space><tab><tab>return NULL;

<space>

<space><tab>return start;

```

save the file, repoman manifest again and emerge drbd-utils.....hopefully should work

----------

## electronvolt

Hi olli.bo

a slightly simpler option is indeed to use /etc/portage/patches. The reason you (and I) never managed to get that to work is that you also need to create a /etc/portage/bashrc file, as the ebuild does not call user patches directly:

```
nano /etc/portage/bashrc
```

```
post_src_prepare() {

    [[ `type -t epatch_user` = "function" ]] && epatch_user

}
```

the patch file(edited as per my previous post) then needs to be placed in /etc/portage/patches/sys-cluster/drbd-utils-8.9.6-r1/

This avoids the need to create an overlay

----------

## fedeliallalinea

I have this in /etc/portage/bashrc

```
pre_src_prepare() {

    [[ ${EAPI:-0} == [012345] ]] || return

    if ! type estack_push > /dev/null 2>&1; then

        local estack_names="eshopts_push eshopts_pop evar_push evar_push_set evar_pop estack_push estack_pop"

        source <(awk "/^# @(FUNCTION|VARIABLE): / { p = 0 } /^# @(FUNCTION|VARIABLE): (${estack_names// /|})\$/ { p = 1 } p { print }" ${PORTDIR}/eclass/estack.eclass)

    fi

    if ! type epatch_user > /dev/null 2>&1; then

        local epatch_names="EPATCH_SOURCE EPATCH_USER_SOURCE epatch_user_death_notice epatch_user epatch"

        source <(awk "/^# @(FUNCTION|VARIABLE): / { p = 0 } /^# @(FUNCTION|VARIABLE): (${epatch_names// /|})\$/ { p = 1 } p { print }" ${PORTDIR}/eclass/epatch.eclass)

    fi

    epatch_user

    for name in $epatch_names; do

        unset $name

    done

    for name in $estack_names; do

        unset $name

    done

}
```

It is a dirty hack for apply user patch for ebuild with EAPI<6

----------

## Hu

 *electronvolt wrote:*   

> the problem is that the forum bbcode does not respect formatting and removes <tabs> Until I find a more elegant solution you will have to edit the patch file and correctly format it

 Text copied from the Post-reply page retains formatting correctly.  Readers should start a reply-with-quote to the post containing the patch, then copy the patch text from the quoted text, then abandon the reply.

----------

## electronvolt

 *Hu wrote:*   

>  *electronvolt wrote:*   the problem is that the forum bbcode does not respect formatting and removes <tabs> Until I find a more elegant solution you will have to edit the patch file and correctly format it Text copied from the Post-reply page retains formatting correctly.  Readers should start a reply-with-quote to the post containing the patch, then copy the patch text from the quoted text, then abandon the reply.

 

Thanks Hu, I knew there must be a way of getting the correctly formatted text.

----------

## olli.bo

OK, thank you! The patch works now and drbd is syncing again!   :Very Happy: 

Will report the solution in Gentoo Bugzilla.

----------

