Skip to content

Commit

Permalink
Fix compilation issues with kernel 4.9 (draios#684)
Browse files Browse the repository at this point in the history
* Fix compilation issues with kernel 4.9

related commits:
torvalds/linux@4c737b4
torvalds/linux@b9d989c

* map io cgroup to blkio, fix for kernels >= 4.8
  • Loading branch information
luca3m authored and Damian Myerscough committed Mar 3, 2017
1 parent 2e7f8a0 commit cd321d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,11 @@ TRACEPOINT_PROBE(syscall_enter_probe, struct pt_regs *regs, long id)
* If this is a 32bit process running on a 64bit kernel (see the CONFIG_IA32_EMULATION
* kernel flag), we switch to the ia32 syscall table.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
if(in_ia32_syscall()) {
#else
if (unlikely(task_thread_info(current)->status & TS_COMPAT)) {
#endif
cur_g_syscall_table = g_syscall_ia32_table;
cur_g_syscall_code_routing_table = g_syscall_ia32_code_routing_table;
socketcall_syscall = __NR_ia32_socketcall;
Expand Down Expand Up @@ -1689,7 +1693,11 @@ TRACEPOINT_PROBE(syscall_exit_probe, struct pt_regs *regs, long ret)
* use 64bit syscall table. On 32bit __NR_execve is equal to __NR_ia32_oldolduname
* which is a very old syscall, not used anymore by most applications
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
if(in_ia32_syscall() && id != __NR_execve) {
#else
if (unlikely((task_thread_info(current)->status & TS_COMPAT) && id != __NR_execve)) {
#endif
cur_g_syscall_table = g_syscall_ia32_table;
cur_g_syscall_code_routing_table = g_syscall_ia32_code_routing_table;
socketcall_syscall = __NR_ia32_socketcall;
Expand Down
14 changes: 12 additions & 2 deletions driver/ppm_fillers.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ static int append_cgroup(const char *subsys_name, int subsys_id, char *buf, int
int subsys_len;
char *path;

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) || LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
int res;
#endif

Expand All @@ -832,7 +832,17 @@ static int append_cgroup(const char *subsys_name, int subsys_id, char *buf, int
return 1;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
// According to /~https://github.com/torvalds/linux/commit/4c737b41de7f4eef2a593803bad1b918dd718b10
// cgroup_path now returns an int again
res = cgroup_path(css->cgroup, buf, *available);
if (res < 0) {
ASSERT(false);
path = "NA";
} else {
path = buf;
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
path = cgroup_path(css->cgroup, buf, *available);
if (!path) {
ASSERT(false);
Expand Down
7 changes: 7 additions & 0 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@ void sinsp_threadinfo::set_cgroups(const char* cgroups, size_t len)
{
subsys = "memory";
}
else if(subsys == "io")
{
// blkio has been renamed just `io`
// in kernel space:
// /~https://github.com/torvalds/linux/commit/c165b3e3c7bb68c2ed55a5ac2623f030d01d9567
subsys = "blkio";
}

m_cgroups.push_back(std::make_pair(subsys, cgroup));
offset += subsys_length + 1 + cgroup.length() + 1;
Expand Down

0 comments on commit cd321d8

Please sign in to comment.