Skip to content

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

@alexeldeib

Description

@alexeldeib

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions