Skip to content

Commit

Permalink
optimizer: transmit container id to optimizer via map
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Tang <[email protected]>
  • Loading branch information
sctb512 committed Aug 24, 2023
1 parent c8c3417 commit d1ec054
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/optimizer/ebpf/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package conn
import (
"bytes"
"encoding/binary"
"strings"
"time"

bpf "github.com/iovisor/gobpf/bcc"
Expand All @@ -18,7 +17,7 @@ import (

import "C"

const templateSource string = `
const sourceCode string = `
#include <net/sock.h>
#include <linux/mount.h>
#include <linux/mm.h>
Expand All @@ -42,6 +41,9 @@ struct buf_s {
char buf[FILE_PATH_LEN*2];
};
char container_id[CONTAINER_ID_LEN];
BPF_ARRAY(id_buf, container_id, 1);
BPF_PERCPU_ARRAY(path_buf, struct buf_s, 1);
BPF_PERCPU_ARRAY(event_buf, struct request_info, 1);
BPF_HASH(vfs_read_start_trace, u64, struct request_info);
Expand All @@ -57,8 +59,13 @@ static int container_id_filter() {
struct task_struct *curr_task;
struct kernfs_node *knode, *pknode;
char container_id[CONTAINER_ID_LEN];
char expected_container_id[CONTAINER_ID_LEN] = "EXCEPTED_CONTAINERD_ID";
char end = 0;
int zero = 0;
char *buf_id = container_id.lookup(&zero);
if (!buf_id) {
return -1;
}
curr_task = (struct task_struct *) bpf_get_current_task();
knode = curr_task->cgroups->subsys[0]->cgroup->kn;
Expand All @@ -68,7 +75,7 @@ static int container_id_filter() {
else
bpf_probe_read(container_id, 1, &end);
return local_strcmp(container_id, expected_container_id);
return local_strcmp(container_id, buf_id);
}
static void fill_file_path(struct file *file, char *file_path) {
Expand Down Expand Up @@ -277,9 +284,7 @@ func kprobeSyscall(m *bpf.Module, syscall string, kprobeEntry string) error {
}

func InitKprobeTable(id string) (*bpf.Module, *bpf.Table, error) {
source := strings.ReplaceAll(templateSource, "EXCEPTED_CONTAINERD_ID", id)

m := bpf.NewModule(source, []string{})
m := bpf.NewModule(sourceCode, []string{})

if err := kprobeSyscall(m, "vfs_read", "trace_vfs_read_entry"); err != nil {
return nil, nil, err
Expand All @@ -300,6 +305,11 @@ func InitKprobeTable(id string) (*bpf.Module, *bpf.Table, error) {
return nil, nil, err
}

byteID := make([]byte, 1)
binary.LittleEndian.PutUint32(byteID, 0)
containerIdTable := bpf.NewTable(m.TableId("id_buf"), m)
containerIdTable.Set(byteID, []byte(id))

table := bpf.NewTable(m.TableId("fille_access_events"), m)

return m, table, nil
Expand Down

0 comments on commit d1ec054

Please sign in to comment.