Blame SOURCES/0010-lib-bpf_legacy-fix-bpffs-mount-when-sys-fs-bpf-exist.patch

d5a8e7
From d1f0f7f4e3e3a372a51e64bdd88f8ddecde1fbbf Mon Sep 17 00:00:00 2001
d5a8e7
Message-Id: <d1f0f7f4e3e3a372a51e64bdd88f8ddecde1fbbf.1633614399.git.aclaudi@redhat.com>
d5a8e7
In-Reply-To: <650694eb0120722499207078f965442ef7343bb1.1633614399.git.aclaudi@redhat.com>
d5a8e7
References: <650694eb0120722499207078f965442ef7343bb1.1633614399.git.aclaudi@redhat.com>
d5a8e7
From: Andrea Claudi <aclaudi@redhat.com>
d5a8e7
Date: Tue, 28 Sep 2021 11:46:43 +0200
d5a8e7
Subject: [PATCH] lib: bpf_legacy: fix bpffs mount when /sys/fs/bpf exists
d5a8e7
MIME-Version: 1.0
d5a8e7
Content-Type: text/plain; charset=UTF-8
d5a8e7
Content-Transfer-Encoding: 8bit
d5a8e7
d5a8e7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1995082
d5a8e7
Upstream Status: iproute2.git commit 2f5825cb
d5a8e7
d5a8e7
commit 2f5825cb38028a14961a79844a069be4e3057eca
d5a8e7
Author: Andrea Claudi <aclaudi@redhat.com>
d5a8e7
Date:   Tue Sep 21 11:33:24 2021 +0200
d5a8e7
d5a8e7
    lib: bpf_legacy: fix bpffs mount when /sys/fs/bpf exists
d5a8e7
d5a8e7
    bpf selftests using iproute2 fails with:
d5a8e7
d5a8e7
    $ ip link set dev veth0 xdp object ../bpf/xdp_dummy.o section xdp_dummy
d5a8e7
    Continuing without mounted eBPF fs. Too old kernel?
d5a8e7
    mkdir (null)/globals failed: No such file or directory
d5a8e7
    Unable to load program
d5a8e7
d5a8e7
    This happens when the /sys/fs/bpf directory exists. In this case, mkdir
d5a8e7
    in bpf_mnt_check_target() fails with errno == EEXIST, and the function
d5a8e7
    returns -1. Thus bpf_get_work_dir() does not call bpf_mnt_fs() and the
d5a8e7
    bpffs is not mounted.
d5a8e7
d5a8e7
    Fix this in bpf_mnt_check_target(), returning 0 when the mountpoint
d5a8e7
    exists.
d5a8e7
d5a8e7
    Fixes: d4fcdbbec9df ("lib/bpf: Fix and simplify bpf_mnt_check_target()")
d5a8e7
    Reported-by: Mingyu Shi <mshi@redhat.com>
d5a8e7
    Reported-by: Jiri Benc <jbenc@redhat.com>
d5a8e7
    Suggested-by: Jiri Benc <jbenc@redhat.com>
d5a8e7
    Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
d5a8e7
    Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
d5a8e7
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
d5a8e7
---
d5a8e7
 lib/bpf_legacy.c | 5 ++++-
d5a8e7
 1 file changed, 4 insertions(+), 1 deletion(-)
d5a8e7
d5a8e7
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
d5a8e7
index 7ec9ce9d..f9dfad6e 100644
d5a8e7
--- a/lib/bpf_legacy.c
d5a8e7
+++ b/lib/bpf_legacy.c
d5a8e7
@@ -513,9 +513,12 @@ static int bpf_mnt_check_target(const char *target)
d5a8e7
 	int ret;
d5a8e7
 
d5a8e7
 	ret = mkdir(target, S_IRWXU);
d5a8e7
-	if (ret && errno != EEXIST)
d5a8e7
+	if (ret) {
d5a8e7
+		if (errno == EEXIST)
d5a8e7
+			return 0;
d5a8e7
 		fprintf(stderr, "mkdir %s failed: %s\n", target,
d5a8e7
 			strerror(errno));
d5a8e7
+	}
d5a8e7
 
d5a8e7
 	return ret;
d5a8e7
 }
d5a8e7
-- 
d5a8e7
2.31.1
d5a8e7