Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a137401d authored by Daniel Borkmann's avatar Daniel Borkmann
Browse files

Merge branch 'bpf-bpftool-mount-tracefs'



Quentin Monnet says:

====================
This series focus on mounting (or not mounting) tracefs with bpftool.

First patch makes bpftool attempt to mount tracefs if tracefs is not
found when running "bpftool prog tracelog".

Second patch adds an option to bpftool to prevent it from attempting
to mount any file system (tracefs or bpffs), in case this behaviour
is undesirable for some users.
====================

Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents 0d7410ea 33221307
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -128,6 +128,10 @@ OPTIONS
	-f, --bpffs
		  Show file names of pinned maps.

	-n, --nomount
		  Do not automatically attempt to mount any virtual file system
		  (such as tracefs or BPF virtual file system) when necessary.

EXAMPLES
========
**# bpftool map show**
+4 −0
Original line number Diff line number Diff line
@@ -161,6 +161,10 @@ OPTIONS
	-m, --mapcompat
		  Allow loading maps with unknown map definitions.

	-n, --nomount
		  Do not automatically attempt to mount any virtual file system
		  (such as tracefs or BPF virtual file system) when necessary.

EXAMPLES
========
**# bpftool prog show**
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ OPTIONS
	-m, --mapcompat
		  Allow loading maps with unknown map definitions.

	-n, --nomount
		  Do not automatically attempt to mount any virtual file system
		  (such as tracefs or BPF virtual file system) when necessary.


SEE ALSO
========
+26 −5
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ void set_max_rlimit(void)
	setrlimit(RLIMIT_MEMLOCK, &rinf);
}

static int mnt_bpffs(const char *target, char *buff, size_t bufflen)
static int
mnt_fs(const char *target, const char *type, char *buff, size_t bufflen)
{
	bool bind_done = false;

@@ -98,15 +99,29 @@ static int mnt_bpffs(const char *target, char *buff, size_t bufflen)
		bind_done = true;
	}

	if (mount("bpf", target, "bpf", 0, "mode=0700")) {
		snprintf(buff, bufflen, "mount -t bpf bpf %s failed: %s",
			 target, strerror(errno));
	if (mount(type, target, type, 0, "mode=0700")) {
		snprintf(buff, bufflen, "mount -t %s %s %s failed: %s",
			 type, type, target, strerror(errno));
		return -1;
	}

	return 0;
}

int mount_tracefs(const char *target)
{
	char err_str[ERR_MAX_LEN];
	int err;

	err = mnt_fs(target, "tracefs", err_str, ERR_MAX_LEN);
	if (err) {
		err_str[ERR_MAX_LEN - 1] = '\0';
		p_err("can't mount tracefs: %s", err_str);
	}

	return err;
}

int open_obj_pinned(char *path, bool quiet)
{
	int fd;
@@ -162,7 +177,13 @@ int mount_bpffs_for_pin(const char *name)
		/* nothing to do if already mounted */
		goto out_free;

	err = mnt_bpffs(dir, err_str, ERR_MAX_LEN);
	if (block_mount) {
		p_err("no BPF file system found, not mounting it due to --nomount option");
		err = -1;
		goto out_free;
	}

	err = mnt_fs(dir, "bpf", err_str, ERR_MAX_LEN);
	if (err) {
		err_str[ERR_MAX_LEN - 1] = '\0';
		p_err("can't mount BPF file system to pin the object (%s): %s",
+7 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ json_writer_t *json_wtr;
bool pretty_output;
bool json_output;
bool show_pinned;
bool block_mount;
int bpf_flags;
struct pinned_obj_table prog_table;
struct pinned_obj_table map_table;
@@ -313,6 +314,7 @@ int main(int argc, char **argv)
		{ "version",	no_argument,	NULL,	'V' },
		{ "bpffs",	no_argument,	NULL,	'f' },
		{ "mapcompat",	no_argument,	NULL,	'm' },
		{ "nomount",	no_argument,	NULL,	'n' },
		{ 0 }
	};
	int opt, ret;
@@ -321,13 +323,14 @@ int main(int argc, char **argv)
	pretty_output = false;
	json_output = false;
	show_pinned = false;
	block_mount = false;
	bin_name = argv[0];

	hash_init(prog_table.table);
	hash_init(map_table.table);

	opterr = 0;
	while ((opt = getopt_long(argc, argv, "Vhpjfm",
	while ((opt = getopt_long(argc, argv, "Vhpjfmn",
				  options, NULL)) >= 0) {
		switch (opt) {
		case 'V':
@@ -354,6 +357,9 @@ int main(int argc, char **argv)
		case 'm':
			bpf_flags = MAPS_RELAX_COMPAT;
			break;
		case 'n':
			block_mount = true;
			break;
		default:
			p_err("unrecognized option '%s'", argv[optind - 1]);
			if (json_output)
Loading