60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
|
|
/* Copyright (c) 2020 Facebook */
|
|
#include "vmlinux.h"
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include <bpf/bpf_core_read.h>
|
|
|
|
#include "replica.h"
|
|
|
|
char LICENSE[] SEC("license") = "Dual BSD/GPL";
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
|
|
__uint(key_size, sizeof(int));
|
|
__uint(value_size, sizeof(int));
|
|
} events SEC(".maps");
|
|
|
|
// 1) notify: __replica_notify(seq, off, len)
|
|
// SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__replica_notify")
|
|
// int BPF_KPROBE(handle_replica_notify, __u64 seq, __u32 off, __u32 len)
|
|
// {
|
|
// struct replica_event evt = {};
|
|
// evt.type = EVENT_CMD_META;
|
|
// evt.meta.seq = seq;
|
|
// evt.meta.off = off;
|
|
// evt.meta.len = len;
|
|
|
|
// bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &evt, sizeof(evt));
|
|
// return 0;
|
|
// }
|
|
|
|
// 2) ssync: __ssync(ip, ip_len, port, seq)
|
|
SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__ssync")
|
|
int BPF_KPROBE(handle_ssync, const __u8 *ip, __u32 ip_len, int port, __u64 seq)
|
|
{
|
|
struct replica_event evt = {};
|
|
evt.type = EVENT_SSYNC;
|
|
evt.sync.seq = seq;
|
|
evt.sync.port = port;
|
|
|
|
__u32 copy_len = ip_len;
|
|
if (copy_len > MAX_IP_LEN) copy_len = MAX_IP_LEN;
|
|
evt.sync.ip_len = copy_len;
|
|
|
|
if (ip)
|
|
bpf_probe_read_user(evt.sync.ip, copy_len, ip);
|
|
|
|
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &evt, sizeof(evt));
|
|
return 0;
|
|
}
|
|
|
|
// 3) sready: __sready()
|
|
SEC("uprobe//home/lian/share/9.1-kvstore/kvstore:__sready")
|
|
int BPF_KPROBE(handle_sready)
|
|
{
|
|
struct replica_event evt = {};
|
|
evt.type = EVENT_SREADY;
|
|
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &evt, sizeof(evt));
|
|
return 0;
|
|
} |