Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic04-pinning-maps: correct solution for assignment 2? #125

Open
alexeldeib opened this issue May 11, 2020 · 3 comments
Open

basic04-pinning-maps: correct solution for assignment 2? #125

alexeldeib opened this issue May 11, 2020 · 3 comments

Comments

@alexeldeib
Copy link

Thanks so much for such an incredible resource!

I've been working through the assignments and I was trying to understand how the provided solution implements what the prompt requires for assignment 2.

I was expecting to remove the call to bpf_object__unpin_maps and replace it with something like https://github.com/xdp-project/xdp-tutorial/tree/master/basic04-pinning-maps#reusing-maps-with-libbpf inside the access check:

/* Existing/previous XDP prog might not have cleaned up */
if (access(map_filename, F_OK ) != -1 ) {
	if (verbose)
		printf(" - Unpinning (remove) prev maps in %s/\n",
				pin_dir);

	int map_fd = bpf_obj_get(map_filename);
	struct bpf_object *obj = bpf_object__open(filename);
	struct bpf_map *map = bpf_object__find_map_by_name(obj, map_name);
	err = bpf_map__reuse_fd(map, map_fd);
	if (err) {
		fprintf(stderr, "ERR: reusing bpf map fd");
		return EXIT_FAIL_BPF;
	}

	err = bpf_map__load(obj);
	if (err) {
		fprintf(stderr, "ERR: loading bpf map");
		return EXIT_FAIL_BPF;
	}
}

The solution doesn't see to do this, it only seems to add a toggle to the CLI flags, am I missing something?

@alexeldeib alexeldeib changed the title basic04-pinning-maps: missing solution for assignment 2 basic04-pinning-maps: correct solution for assignment 2? May 11, 2020
@tohojo
Copy link
Member

tohojo commented May 11, 2020

Hmm, yeah, you're right that seems to be an oversight. However, libbpf has since introduced automatic re-use of pinned maps, so I guess we should switch this whole assignment over to explaining that. There are a couple of these kinds of tweaks, so taking a full pass through the tutorial and doing a few updates is really needed... It's on my list :)

@alexeldeib
Copy link
Author

I'd be happy to help update the assignment to reflect that if it's welcome, with the caveat that I'm familiar with BPF but neither an XDP pro nor kernel dev :)

I was looking around for any libbpf docs indicating that change or a patchset, any chance you have some reference material? If not, I can take a stab at it without. I found some tangential patchsets but not this diff yet.

@tohojo
Copy link
Member

tohojo commented May 12, 2020

Hmm, only reference is this commit: libbpf/libbpf@e7d860d

It requires BTF-defined maps, though, which we're not using in the tutorial either since that in turn depends on LLVM9. We haven't decided whether we're OK to depend on LLVM9 for the entire tutorial or if we should be splitting things based on version. So feel free to take a stab at defining something like this, but be prepared to move things around a bit if you do :)

If you do want to try it, you'll also need an updated libbpf; see #126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants