File: pinning_devmap_reuse.c

package info (click to toggle)
linux 6.18.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,212 kB
  • sloc: ansic: 26,783,651; asm: 272,129; sh: 148,799; python: 79,242; makefile: 57,742; perl: 36,527; xml: 19,542; cpp: 5,911; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (50 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: GPL-2.0

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <test_progs.h>


#include "test_pinning_devmap.skel.h"

void test_pinning_devmap_reuse(void)
{
	const char *pinpath1 = "/sys/fs/bpf/pinmap1";
	const char *pinpath2 = "/sys/fs/bpf/pinmap2";
	struct test_pinning_devmap *skel1 = NULL, *skel2 = NULL;
	int err;
	DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);

	/* load the object a first time */
	skel1 = test_pinning_devmap__open_and_load();
	if (!ASSERT_OK_PTR(skel1, "skel_load1"))
		goto out;

	/* load the object a second time, re-using the pinned map */
	skel2 = test_pinning_devmap__open_and_load();
	if (!ASSERT_OK_PTR(skel2, "skel_load2"))
		goto out;

	/* we can close the reference safely without
	 * the map's refcount falling to 0
	 */
	test_pinning_devmap__destroy(skel1);
	skel1 = NULL;

	/* now, swap the pins */
	err = renameat2(0, pinpath1, 0, pinpath2, RENAME_EXCHANGE);
	if (!ASSERT_OK(err, "swap pins"))
		goto out;

	/* load the object again, this time the re-use should fail */
	skel1 = test_pinning_devmap__open_and_load();
	if (!ASSERT_ERR_PTR(skel1, "skel_load3"))
		goto out;

out:
	unlink(pinpath1);
	unlink(pinpath2);
	test_pinning_devmap__destroy(skel1);
	test_pinning_devmap__destroy(skel2);
}