已有数据同步功能完成

This commit is contained in:
1iaan
2026-01-29 10:47:24 +00:00
parent fe257cafec
commit 2bdb48d63d
27 changed files with 1134 additions and 139 deletions

103
ebpf/c/replica.bpf.c Normal file
View File

@@ -0,0 +1,103 @@
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright (c) 2020 Facebook */
#include <linux/bpf.h>
#include <linux/ptrace.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "replica.h"
char LICENSE[] SEC("license") = "Dual BSD/GPL";
int my_pid = 0;
struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(int));
} channel SEC(".maps");
SEC("uprobe/kvs_create_snapshot_async")
int uprobe_create_snapshot_async(struct pt_regs *ctx)
{
struct event ev;
__builtin_memset(&ev, 0, sizeof(ev));
const char *ip;
__u32 port;
ev.type = EVENT_CREATE_SNAPSHOT_ASYNC;
ip = (const char *)PT_REGS_PARM1(ctx);
port = (__u32)PT_REGS_PARM2(ctx);
bpf_probe_read_user_str(ev.data.sync.ip,
sizeof(ev.data.sync.ip),
ip);
ev.data.sync.port = port;
bpf_perf_event_output(ctx, &channel,
BPF_F_CURRENT_CPU,
&ev, sizeof(ev));
return 0;
}
SEC("uprobe/__compeleted_cmd")
int uprobe_completed_cmd(struct pt_regs *ctx)
{
struct event ev;
__builtin_memset(&ev, 0, sizeof(ev));
const __u8 *cmd;
__u32 len;
ev.type = EVENT_COMPLETED_CMD;
cmd = (const __u8 *)PT_REGS_PARM1(ctx);
len = (__u32)PT_REGS_PARM2(ctx);
if (len > sizeof(ev.data.cmd.cmd))
len = sizeof(ev.data.cmd.cmd);
ev.data.cmd.len = len;
bpf_probe_read_user(ev.data.cmd.cmd, len, cmd);
bpf_perf_event_output(ctx, &channel,
BPF_F_CURRENT_CPU,
&ev, sizeof(ev));
return 0;
}
SEC("uprobe/__create_snapshot_ok")
int uprobe_create_snapshot_ok(struct pt_regs *ctx)
{
struct event ev;
__builtin_memset(&ev, 0, sizeof(ev));
const char *array_file;
const char *rbtree_file;
const char *hash_file;
ev.type = EVENT_CREATE_SNAPSHOT_OK;
array_file = (const char *)PT_REGS_PARM1(ctx);
rbtree_file = (const char *)PT_REGS_PARM2(ctx);
hash_file = (const char *)PT_REGS_PARM3(ctx);
bpf_probe_read_user_str(ev.data.ok.array_file,
sizeof(ev.data.ok.array_file),
array_file);
bpf_probe_read_user_str(ev.data.ok.rbtree_file,
sizeof(ev.data.ok.rbtree_file),
rbtree_file);
bpf_probe_read_user_str(ev.data.ok.hash_file,
sizeof(ev.data.ok.hash_file),
hash_file);
bpf_perf_event_output(ctx, &channel,
BPF_F_CURRENT_CPU,
&ev, sizeof(ev));
return 0;
}