Skip to contentSkip to conversation

fix drbd-utils minor issues

PATCH In review Heming Zhao 2 participants 9 messages May 15, 2025 – May 29, 2025 DRBD driver

lore
Share & tools
lore
#0 lore raw

v2 cover fix drbd-utils minor issues

This patchset fixes two issues:
- configure reports WARNING for SuSe-release file
- lock file permission issue in SELinux env

v1->v2
factor out shared code for creating lfname
add free lfname job after unlink()

Heming Zhao (2):
build: changing SUSE release file
remove lock file after using it

 configure.ac              |  4 ++--
 user/shared/drbdmeta.c    |  3 +++
 user/shared/shared_tool.c | 40 +++++++++++++++++++++++++++++----------
 user/shared/shared_tool.h |  2 +-
 user/v84/drbdsetup.c      |  2 +-
 user/v9/drbdsetup.c       |  2 +-
 6 files changed, 38 insertions(+), 15 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 build: changing SUSE release file

This commit changes /etc/SuSe-release to /etc/os-release. The SuSe-release file disappeared a long time ago.

---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
index 282fdf1584e3..883fe3e5cdb3 100644
@@ -402,7 +402,7 @@ else
    if test -z $DISTRO; then
       AC_CHECK_FILE(/etc/redhat-release, [DISTRO="redhat"])
       AC_CHECK_FILE(/etc/debian_version, [DISTRO="debian"])
-      AC_CHECK_FILE(/etc/SuSE-release, [DISTRO="suse"])
+      AC_CHECK_FILE(/etc/os-release, [DISTRO="suse"])
    fi
    case "$DISTRO" in
         redhat)
@@ -439,7 +439,7 @@ else
 	    # RPM_REQ_HEARTBEAT="Requires: heartbeat"
 
 	    # Unfortunately gcc on SLES9 is broken with -O2. Works with -O1
-	    if grep -q 'VERSION = 9' /etc/SuSE-release; then
+	    if grep -q 'VERSION = 9' /etc/os-release; then
 		    CFLAGS="-g -O1"
 	    fi
 	    ;;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/2] build: changing SUSE release file

Quoted 13 lines · Heming Zhao

This commit changes /etc/SuSe-release to /etc/os-release. The SuSe-release file disappeared a long time ago.

---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +0 -0
index 282fdf1584e3..883fe3e5cdb3 100644

configure.ac else · line 405

Quoted 5 lines
configure.ac +1 -1
@@ -402,7 +402,7 @@ else
    if test -z $DISTRO; then
       AC_CHECK_FILE(/etc/redhat-release, [DISTRO="redhat"])
       AC_CHECK_FILE(/etc/debian_version, [DISTRO="debian"])
-      AC_CHECK_FILE(/etc/SuSE-release, [DISTRO="suse"])
+      AC_CHECK_FILE(/etc/os-release, [DISTRO="suse"])

Hi,

everything that has a /etc/os-release (which by now is basically every distribution on this planet) is suse? No.

This (not only this) part of the automagic in drbd-utils is a mess and I'm currently in the process of cleaning that up a bit. I will not take this patch as is, IMO it is just wrong, please just wait, this should improve in a week or two.

Regards, rck

#3 lore raw

Re: [PATCH v2 1/2] build: changing SUSE release file

Quoted 25 lines · Roland Kammerer
Quoted 13 lines · Heming Zhao

This commit changes /etc/SuSe-release to /etc/os-release. The SuSe-release file disappeared a long time ago.

---
  configure.ac | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +0 -0
index 282fdf1584e3..883fe3e5cdb3 100644

configure.ac else · line 405

Quoted 5 lines
configure.ac +1 -1
@@ -402,7 +402,7 @@ else
     if test -z $DISTRO; then
        AC_CHECK_FILE(/etc/redhat-release, [DISTRO="redhat"])
        AC_CHECK_FILE(/etc/debian_version, [DISTRO="debian"])
-      AC_CHECK_FILE(/etc/SuSE-release, [DISTRO="suse"])
+      AC_CHECK_FILE(/etc/os-release, [DISTRO="suse"])

Hi,

everything that has a /etc/os-release (which by now is basically every distribution on this planet) is suse? No.

Quoted 6 lines

This (not only this) part of the automagic in drbd-utils is a mess and I'm currently in the process of cleaning that up a bit. I will not take this patch as is, IMO it is just wrong, please just wait, this should improve in a week or two.

Regards, rck

Thanks for the explanation.
Indeed, I didn't check other distribution styles. Let's wait for your fix for this build issue.

- Heming

#4 lore raw

PATCH v2 2/2 remove lock file after using it

In reply to Heming Zhao

In a SELinux env, if a user runs as root to set up a DRBD device, it will leave a lock file in "/var/run/drbd/lock/". Then HA pacemaker will fail to set up DRBD because of a permission issue.

This commit removes the lock file when drbdsetup and drbdmeta close the lock fd.

---
 user/shared/drbdmeta.c    |  3 +++
 user/shared/shared_tool.c | 40 +++++++++++++++++++++++++++++----------
 user/shared/shared_tool.h |  2 +-
 user/v84/drbdsetup.c      |  2 +-
 user/v9/drbdsetup.c       |  2 +-
 5 files changed, 36 insertions(+), 13 deletions(-)
user/shared/drbdmeta.c +3 -0
index 099592a530da..c84c09abef86 100644
@@ -5482,6 +5482,9 @@ int main(int argc, char **argv)
 	if (minor_attached)
 		fprintf(stderr, "# Output might be stale, since minor %d is attached\n", cfg->minor);
 
+	if ((cfg->minor != -1) && (cfg->lock_fd != -1))
+		dt_unlock_drbd(cfg->lock_fd, cfg->minor);
+
 	// dummy bool normalization to not return negative values, the usual "FIXME sane exit codes" still applies */
 	return !!rv;
 	/* and if we want an explicit free,
user/shared/shared_tool.c +30 -10
index 20598132a0ac..b45d71379d96 100644
@@ -759,9 +759,26 @@ void ensure_dir(const char *dirname)
 	}
 }
 
+static char *get_lock_filename(int minor, int check_dir)
+{
+	int sz;
+	char *lfname;
+
+	if (check_dir)
+		ensure_dir(drbd_lock_dir());
+
+	sz = asprintf(&lfname, "%s/drbd-%d-%d",
+		      drbd_lock_dir(), LANANA_DRBD_MAJOR, minor);
+	if (sz < 0) {
+		perror("");
+		exit(20);
+	}
+	return lfname;
+}
+
 int dt_lock_drbd(int minor)
 {
-	int sz, lfd;
+	int lfd;
 	char *lfname;
 
 	/* THINK.
@@ -777,14 +794,7 @@ int dt_lock_drbd(int minor)
 	 * We should store something in the meta data to detect such abuses.
 	 */
 
-	ensure_dir(drbd_lock_dir());
-	sz = asprintf(&lfname, "%s/drbd-%d-%d",
-		      drbd_lock_dir(), LANANA_DRBD_MAJOR, minor);
-	if (sz < 0) {
-		perror("");
-		exit(20);
-	}
-
+	lfname = get_lock_filename(minor, 1);
 	lfd = get_fd_lockfile_timeout(lfname, 1);
 	free (lfname);
 	if (lfd < 0)
@@ -793,10 +803,20 @@ int dt_lock_drbd(int minor)
 }
 
 /* ignore errors */
-void dt_unlock_drbd(int lock_fd)
+void dt_unlock_drbd(int lock_fd, int minor)
 {
+	int ret;
+	char *lfname;
+
 	if (lock_fd >= 0)
 		unlock_fd(lock_fd);
+
+	lfname = get_lock_filename(minor, 0);
+	ret = unlink(lfname);
+	free(lfname);
+	if (ret < 0) {
+		perror("unlink");
+	}
 }
 
 void dt_print_gc(const uint32_t* gen_cnt)
user/shared/shared_tool.h +1 -1
index 3dedf79683f5..44f10b549a77 100644
@@ -108,7 +108,7 @@ extern bool addr_scope_local(const char *input);
 extern unsigned long long m_strtoll(const char* s,const char def_unit);
 extern int only_digits(const char *s);
 extern int dt_lock_drbd(int minor);
-extern void dt_unlock_drbd(int lock_fd);
+extern void dt_unlock_drbd(int lock_fd, int minor);
 extern int dt_minor_of_dev(const char *device);
 extern void dt_print_gc(const uint32_t* gen_cnt);
 extern void dt_pretty_print_gc(const uint32_t* gen_cnt);
user/v84/drbdsetup.c +1 -1
index 9127a4462a0e..530af7b70b95 100644
@@ -3715,7 +3715,7 @@ int main(int argc, char **argv)
 	rv = cmd->function(cmd, argc, argv);
 
 	if ((context & CTX_MINOR) && !cmd->lockless)
-		dt_unlock_drbd(lock_fd);
+		dt_unlock_drbd(lock_fd, minor);
 	return rv;
 }
 #endif
user/v9/drbdsetup.c +1 -1
index 8aa9b7c48a6a..e7fa4d8bad7b 100644
@@ -4779,6 +4779,6 @@ int drbdsetup_main(int argc, char **argv)
 	rv = cmd->function(cmd, argc, argv);
 
 	if ((context & CTX_MINOR) && !cmd->lockless)
-		dt_unlock_drbd(lock_fd);
+		dt_unlock_drbd(lock_fd, minor);
 	return rv;
 }
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 2/2] remove lock file after using it

Quoted 3 lines · Heming Zhao

In a SELinux env, if a user runs as root to set up a DRBD device, it will leave a lock file in "/var/run/drbd/lock/". Then HA pacemaker will fail to set up DRBD because of a permission issue.

Sorry, but that needs more explanation. I wonder why it works for everybody else including our SuSE customers but would require changes for you? What exactly (sles versions, pacemaker versions,...) do I need to reproduce this?

Quoted 7 lines

/* ignore errors */

user/shared/shared_tool.c +4 -1
-void dt_unlock_drbd(int lock_fd)
+void dt_unlock_drbd(int lock_fd, int minor)
 {
+	int ret;
+	char *lfname;
+

user/shared/shared_tool.c int dt_lock_drbd(int minor) · line 820

Quoted 10 lines
user/shared/shared_tool.c +7 -0
 	if (lock_fd >= 0)
 		unlock_fd(lock_fd);
+
+	lfname = get_lock_filename(minor, 0);
+	ret = unlink(lfname);
+	free(lfname);
+	if (ret < 0) {
+		perror("unlink");
+	}
 }

As I don't understand why you would need these changes in the first place I did not look into the patch too closely, but: You first unlock and then unlink? Shouldn't that be the other way round? As is you would create a race I guess. But first things first: why do you need that at all?

Regards, rck

P.S.: it is fine to send user land patches here, but the main focus is on kernel level coordination, feel free to send patches via github.

#6 lore raw

Re: [PATCH v2 2/2] remove lock file after using it

Hello,

Quoted 9 lines · Roland Kammerer
Quoted 3 lines · Heming Zhao

In a SELinux env, if a user runs as root to set up a DRBD device, it will leave a lock file in "/var/run/drbd/lock/". Then HA pacemaker will fail to set up DRBD because of a permission issue.

Sorry, but that needs more explanation. I wonder why it works for everybody else including our SuSE customers but would require changes for you? What exactly (sles versions, pacemaker versions,...) do I need to reproduce this?

Sorry for the late reply, I took some time to set up a reproducible env for this issue.

This issue was originally reported by the SUSE QA team, and occurs in SLE16 (which is not yet released). However, I also reproduced it on the latest openSUSE tumbleweed.

please refer to the final section of this mail for the reproduction steps.

Quoted 16 lines
Quoted 16 lines

/* ignore errors */

user/shared/shared_tool.c +10 -1
-void dt_unlock_drbd(int lock_fd)
+void dt_unlock_drbd(int lock_fd, int minor)
  {
+	int ret;
+	char *lfname;
+
  	if (lock_fd >= 0)
  		unlock_fd(lock_fd);
+
+	lfname = get_lock_filename(minor, 0);
+	ret = unlink(lfname);
+	free(lfname);
+	if (ret < 0) {
+		perror("unlink");
Quoted 8 lines

user/shared/shared_tool.c int dt_lock_drbd(int minor) · line 820

Quoted 2 lines
user/shared/shared_tool.c +1 -0
+	}
  }

As I don't understand why you would need these changes in the first place I did not look into the patch too closely, but: You first unlock and then unlink? Shouldn't that be the other way round? As is you would create a race I guess. But first things first: why do you need that at all?

I am not quit following you. From your description, it appears that drbd-utils expects the lock file (/var/run/drbd/lock/xxx) to persist throughout the system's runtime.
If drbd-utils deletes the file after every close() call, this could potentially trigger a race condition in DRBD, correct?

This patch removes the lock file after close(). From the code logic perspective, the lock file can be safely removed after close(). Could you point out a potential race condition?

Quoted 5 lines

Regards, rck

P.S.: it is fine to send user land patches here, but the main focus is on kernel level coordination, feel free to send patches via github.

OK, I will submit the next patch via github.

---- following are the reproducible steps -----

## setup vm

create two VMs:
- 4 VCPU, 4G mem, one 100M *shared* disk for sbd, one 1G disk for drbd.
- the sbd is using scsi bus type, drbd disk is using virtio bus type

## install softwares

I use opensuse tumbleweed latest ISO:

Quoted 1 line

openSUSE-Tumbleweed-DVD-x86_64-Snapshot20250522-Media.iso

on both nodes:
zypper in pdsh crmsh pacemaker corosync libcsync-plugin-sftp drbd-utils

## setup cluster

setup vm hostname.
node1: hostnamectl set-hostname tw25-1
node2: hostnamectl set-hostname tw25-2

edit "/etc/hosts", add 2-nodes ip and hostname in it:
192.168.122.175 tw25-1
192.168.122.214 tw25-2

cleanup disk:
wipefs -a /dev/sdb /dev/vdb
(sdb is 100MB shared disk for sbd, vdb is 1GB disk for drbd.)

on node1:
crm cluster init -s <sbd dev> -y

from my env: crm cluster init -s /dev/sda -y

on node2:
crm cluster join -c <node1-ip>

from my env: crm cluster join -c 192.168.122.175

use "crm status full" to check cluster status.

ref: https://documentation.suse.com/sle-ha/15-SP6/html/SLE-HA-all/article-installation.html

## setup drbd

on both node, create "/etc/drbd.d/drbd_passive.res"

```
resource drbd_passive {
  protocol  C;
  device    /dev/drbd_passive minor 0;
  meta-disk internal;

  on tw25-1 {
    address 192.168.122.134:7788;
    disk    "/dev/disk/by-path/virtio-pci-0000:0b:00.0";
    node-id 0;
  }

  on tw25-2 {
    address 192.168.122.177:7788;
    disk    "/dev/disk/by-path/virtio-pci-0000:0b:00.0";
    node-id 1;
  }

  disk {
    resync-rate 10M;
    no-md-flushes;
    no-disk-flushes;
    no-disk-barrier;
  }

  connection-mesh {
    hosts tw25-1 tw25-2;
  }
}
```

- Run in both nodes: wipefs -a /dev/<drbd-dev>
- Run in both nodes: drbdadm create-md drbd_passive
- Run in both nodes: drbdadm up drbd_passive
- Run in node 1: drbdadm -- --overwrite-data-of-peer --force primary drbd_passive
- Run in both nodes: drbdadm status drbd_passive. Continue running this command in both nodes until the devices are in sync.
- Run in node 1: drbdadm secondary drbd_passive
- Run in both nodes: drbdadm down drbd_passive

please note, after drbdadm down drbd_passive, drbdadm left a lock file in "/var/run/drbd/lock/". This is the key to reproduce this bug. if you remove the lock file, the issue will never be triggered.

## create/start the drbd resource

on node1:

Quoted 1 line
# crm config edit

add following config:

```
primitive drbd_passive ocf:linbit:drbd \
         params drbd_resource=drbd_passive ignore_missing_notifications=true
clone ms_drbd_passive drbd_passive \
         meta clone-max=2 clone-node-max=1 notify=true promotable=true
```

the journal log output:

```
drbd(drbd_passive)[4860]: ERROR: drbd_passive: Called drbdadm -c /etc/drbd.conf check-resize drbd_passive
drbd(drbd_passive)[4864]: ERROR: drbd_passive: Exit code 20
drbd(drbd_passive)[4868]: ERROR: drbd_passive: Command output:
drbd(drbd_passive)[4872]: ERROR: drbd_passive: Command stderr: open(/var/run/drbd/lock/drbd-147-0): Permission denied
                 Maybe 'rm -f Maybe 'rm -f /drbd/lock/drbd-147-0): Permission denied
                 ', or check sysctl fs.protected_regular
                 Command 'drbdmeta 0 v09 /dev/disk/by-path/virtio-pci-0000:06:00.0 internal check-resize' terminated with exit code 20
```

you can re-trigger this issue by

```
# crm resource stop ms_drbd_passive
# crm resource stop drbd_passive
# crm resource cleanup drbd_passive
# crm resource cleanup ms_drbd_passive
# crm resource start drbd_passive  <== failure, block next command
# crm resource start ms_drbd_passive <== failure
```

## softwares version

```
# rpm -qa | grep pacemaker
pacemaker-schemas-3.0.0+20250331.008a7d1784-1.1.noarch
pacemaker-libs-3.0.0+20250331.008a7d1784-1.1.x86_64
pacemaker-cli-3.0.0+20250331.008a7d1784-1.1.x86_64
pacemaker-3.0.0+20250331.008a7d1784-1.1.x86_64

# rpm -qa | grep corosync
corosync-libs-3.1.9-2.1.x86_64
corosync-3.1.9-2.1.x86_64

# rpm -qa | grep crmsh
crmsh-scripts-5.0.0+20250522.ffecd6cb-1.1.noarch
crmsh-5.0.0+20250522.ffecd6cb-1.1.noarch

# rpm -qa | grep drbd
drbd-selinux-9.29.0-3.1.x86_64
drbd-utils-9.29.0-3.1.x86_64
drbd-9.1.23-4.4.x86_64
drbd-kmp-default-9.1.23_k6.14.6_1-4.4.x86_64

# uname -a
Linux tw25-3 6.14.6-1-default #1 SMP PREEMPT_DYNAMIC Tue May 13 09:56:22 UTC 2025 (ad69173) x86_64 x86_64 x86_64 GNU/Linux
```

Thanks,
Heming

#7 lore raw

Re: [PATCH v2 2/2] remove lock file after using it

Quoted 11 lines · Heming Zhao

Hello,

Quoted 6 lines · Roland Kammerer
Quoted 3 lines · Heming Zhao

In a SELinux env, if a user runs as root to set up a DRBD device, it will leave a lock file in "/var/run/drbd/lock/". Then HA pacemaker will fail to set up DRBD because of a permission issue.

... ...

Quoted 9 lines

---- following are the reproducible steps -----

## setup vm

create two VMs:
- 4 VCPU, 4G mem, one 100M *shared* disk for sbd, one 1G disk for drbd.
- the sbd is using scsi bus type, drbd disk is using virtio bus type

I forgot to mention that to reproduce this issue, please make sure SELinux is enabled (default configuration) and the port 7799 is open (or disable firewalld).

- Heming

#8 lore raw

Re: [PATCH v2 2/2] remove lock file after using it

In reply to Heming Zhao
Quoted 11 lines · Heming Zhao

Hello,

Quoted 6 lines · Roland Kammerer
Quoted 3 lines · Heming Zhao

In a SELinux env, if a user runs as root to set up a DRBD device, it will leave a lock file in "/var/run/drbd/lock/". Then HA pacemaker will fail to set up DRBD because of a permission issue.

... ...

Quoted 9 lines

---- following are the reproducible steps -----

## setup vm

create two VMs:
- 4 VCPU, 4G mem, one 100M *shared* disk for sbd, one 1G disk for drbd.
- the sbd is using scsi bus type, drbd disk is using virtio bus type

I forgot to mention that to reproduce this issue, please make sure SELinux is enabled (default configuration) and the port 7799 is open (or disable firewalld).

- Heming