]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
libbpf: add bpf_object__load_xattr() API function to pass log_level
authorQuentin Monnet <quentin.monnet@netronome.com>
Fri, 24 May 2019 10:36:47 +0000 (11:36 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 28 May 2019 09:03:26 +0000 (11:03 +0200)
libbpf was recently made aware of the log_level attribute for programs,
used to specify the level of information expected to be dumped by the
verifier. Function bpf_prog_load_xattr() got support for this log_level
parameter.

But some applications using libbpf rely on another function to load
programs, bpf_object__load(), which does accept any parameter for log
level. Create an API function based on bpf_object__load(), but accepting
an "attr" object as a parameter. Then add a log_level field to that
object, so that applications calling the new bpf_object__load_xattr()
can pick the desired log level.

v3:
- Rewrite commit log.

v2:
- We are in a new cycle, bump libbpf extraversion number.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/Makefile
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h
tools/lib/bpf/libbpf.map

index a2aceadf68db52f780271e41b5d4ecc8ce314eb2..9312066a1ae380b0ce9b9abb6c5923d86d047bd8 100644 (file)
@@ -3,7 +3,7 @@
 
 BPF_VERSION = 0
 BPF_PATCHLEVEL = 0
-BPF_EXTRAVERSION = 3
+BPF_EXTRAVERSION = 4
 
 MAKEFLAGS += --no-print-directory
 
index fd5905ac2ec37a58e8269f0d26a0ca4377053849..ca4432f5b067ef39cdcc2f6518901c5cc6f0f65d 100644 (file)
@@ -2224,7 +2224,7 @@ static bool bpf_program__is_function_storage(struct bpf_program *prog,
 }
 
 static int
-bpf_object__load_progs(struct bpf_object *obj)
+bpf_object__load_progs(struct bpf_object *obj, int log_level)
 {
        size_t i;
        int err;
@@ -2232,6 +2232,7 @@ bpf_object__load_progs(struct bpf_object *obj)
        for (i = 0; i < obj->nr_programs; i++) {
                if (bpf_program__is_function_storage(&obj->programs[i], obj))
                        continue;
+               obj->programs[i].log_level = log_level;
                err = bpf_program__load(&obj->programs[i],
                                        obj->license,
                                        obj->kern_version);
@@ -2383,10 +2384,14 @@ int bpf_object__unload(struct bpf_object *obj)
        return 0;
 }
 
-int bpf_object__load(struct bpf_object *obj)
+int bpf_object__load_xattr(struct bpf_object_load_attr *attr)
 {
+       struct bpf_object *obj;
        int err;
 
+       if (!attr)
+               return -EINVAL;
+       obj = attr->obj;
        if (!obj)
                return -EINVAL;
 
@@ -2399,7 +2404,7 @@ int bpf_object__load(struct bpf_object *obj)
 
        CHECK_ERR(bpf_object__create_maps(obj), err, out);
        CHECK_ERR(bpf_object__relocate(obj), err, out);
-       CHECK_ERR(bpf_object__load_progs(obj), err, out);
+       CHECK_ERR(bpf_object__load_progs(obj, attr->log_level), err, out);
 
        return 0;
 out:
@@ -2408,6 +2413,15 @@ int bpf_object__load(struct bpf_object *obj)
        return err;
 }
 
+int bpf_object__load(struct bpf_object *obj)
+{
+       struct bpf_object_load_attr attr = {
+               .obj = obj,
+       };
+
+       return bpf_object__load_xattr(&attr);
+}
+
 static int check_path(const char *path)
 {
        char *cp, errmsg[STRERR_BUFSIZE];
index 5abc2375defd6f4fe1a47e647102d80e3f5d4074..1af0d48178c8a0a2129ca0790246fd7b32a7833b 100644 (file)
@@ -89,8 +89,14 @@ LIBBPF_API int bpf_object__unpin_programs(struct bpf_object *obj,
 LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path);
 LIBBPF_API void bpf_object__close(struct bpf_object *object);
 
+struct bpf_object_load_attr {
+       struct bpf_object *obj;
+       int log_level;
+};
+
 /* Load/unload object into/from kernel */
 LIBBPF_API int bpf_object__load(struct bpf_object *obj);
+LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr);
 LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
 LIBBPF_API const char *bpf_object__name(struct bpf_object *obj);
 LIBBPF_API unsigned int bpf_object__kversion(struct bpf_object *obj);
index 8bf51d0a6072a9e8d945533dc695a33f31c4ad3d..46dcda89df211289669a88d21522d7833f13fe78 100644 (file)
@@ -171,4 +171,5 @@ LIBBPF_0.0.4 {
                btf_dump__free;
                btf_dump__new;
                btf__parse_elf;
+               bpf_object__load_xattr;
 } LIBBPF_0.0.3;