]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/cgroups/cgroup2_devices.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 /* Parts of this taken from systemd's implementation. */
5 #ifndef __LXC_CGROUP2_DEVICES_H
6 #define __LXC_CGROUP2_DEVICES_H
12 #ifndef FUSE_USE_VERSION
13 #define FUSE_USE_VERSION 26
16 #define _FILE_OFFSET_BITS 64
24 #include <sys/syscall.h>
25 #include <sys/types.h>
28 #ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
29 #include <linux/bpf.h>
30 #include <linux/filter.h>
34 #if !(defined __NR_bpf && __NR_bpf > 0)
40 #elif defined __x86_64__
42 #elif defined __aarch64__
46 #elif defined __sparc__
48 #elif defined __s390__
50 #elif defined __tilegx__
53 #warning "__NR_bpf not defined for your architecture"
59 static inline int missing_bpf(int cmd
, union bpf_attr
*attr
, size_t size
)
62 return (int)syscall(__NR_bpf
, cmd
, attr
, size
);
69 #define bpf missing_bpf
77 size_t n_instructions
;
78 #ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
79 struct bpf_insn
*instructions
;
84 uint32_t attached_flags
;
87 #ifdef HAVE_STRUCT_BPF_CGROUP_DEV_CTX
88 struct bpf_program
*bpf_program_new(uint32_t prog_type
);
89 int bpf_program_init(struct bpf_program
*prog
);
90 int bpf_program_append_device(struct bpf_program
*prog
,
91 struct device_item
*device
);
92 int bpf_program_finalize(struct bpf_program
*prog
);
93 int bpf_program_cgroup_attach(struct bpf_program
*prog
, int type
,
94 const char *path
, uint32_t flags
);
95 int bpf_program_cgroup_detach(struct bpf_program
*prog
);
96 void bpf_program_free(struct bpf_program
*prog
);
97 bool bpf_devices_cgroup_supported(void);
98 static inline void __auto_bpf_program_free__(struct bpf_program
**prog
)
101 bpf_program_free(*prog
);
106 static inline struct bpf_program
*bpf_program_new(uint32_t prog_type
)
112 static inline int bpf_program_init(struct bpf_program
*prog
)
118 static inline int bpf_program_append_device(struct bpf_program
*prog
, char type
,
119 int major
, int minor
,
120 const char *access
, int allow
)
126 static inline int bpf_program_finalize(struct bpf_program
*prog
)
132 static inline int bpf_program_cgroup_attach(struct bpf_program
*prog
, int type
,
133 const char *path
, uint32_t flags
)
139 static inline int bpf_program_cgroup_detach(struct bpf_program
*prog
)
145 static inline void bpf_program_free(struct bpf_program
*prog
)
150 static inline bool bpf_devices_cgroup_supported(void)
155 static inline void __auto_bpf_program_free__(struct bpf_program
**prog
)
161 #define __do_bpf_program_free \
162 __attribute__((__cleanup__(__auto_bpf_program_free__)))
164 #endif /* __LXC_CGROUP2_DEVICES_H */