Commit a777e18f authored by Yafang Shao's avatar Yafang Shao Committed by Andrii Nakryiko
Browse files

bpftool: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK



We have switched to memcg-based memory accouting and thus the rlimit is
not needed any more. LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK was introduced in
libbpf for backward compatibility, so we can use it instead now.

libbpf_set_strict_mode always return 0, so we don't need to check whether
the return value is 0 or not.

Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220409125958.92629-4-laoar.shao@gmail.com
parent b858ba8c
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include <linux/magic.h>
#include <net/if.h>
#include <sys/mount.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/vfs.h>

@@ -119,13 +118,6 @@ static bool is_bpffs(char *path)
	return (unsigned long)st_fs.f_type == BPF_FS_MAGIC;
}

void set_max_rlimit(void)
{
	struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };

	setrlimit(RLIMIT_MEMLOCK, &rinf);
}

static int
mnt_fs(const char *target, const char *type, char *buff, size_t bufflen)
{
+0 −2
Original line number Diff line number Diff line
@@ -1136,8 +1136,6 @@ static int do_probe(int argc, char **argv)
	__u32 ifindex = 0;
	char *ifname;

	set_max_rlimit();

	while (argc) {
		if (is_prefix(*argv, "kernel")) {
			if (target != COMPONENT_UNSPEC) {
+3 −3
Original line number Diff line number Diff line
@@ -507,9 +507,9 @@ int main(int argc, char **argv)
		 * It will still be rejected if users use LIBBPF_STRICT_ALL
		 * mode for loading generated skeleton.
		 */
		ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
		if (ret)
			p_err("failed to enable libbpf strict mode: %d", ret);
		libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
	} else {
		libbpf_set_strict_mode(LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK);
	}

	argc -= optind;
+0 −2
Original line number Diff line number Diff line
@@ -102,8 +102,6 @@ int detect_common_prefix(const char *arg, ...);
void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep);
void usage(void) __noreturn;

void set_max_rlimit(void);

int mount_tracefs(const char *target);

struct obj_ref {
+0 −2
Original line number Diff line number Diff line
@@ -1342,8 +1342,6 @@ static int do_create(int argc, char **argv)
		goto exit;
	}

	set_max_rlimit();

	fd = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, &attr);
	if (fd < 0) {
		p_err("map create failed: %s", strerror(errno));
Loading