Skip to content

Commit

Permalink
libc::statx -> our artisan StatResult
Browse files Browse the repository at this point in the history
  • Loading branch information
charmoniumQ committed Oct 16, 2024
1 parent 9469603 commit 1b50cdd
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 127 deletions.
6 changes: 3 additions & 3 deletions probe_src/frontend/cli/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Dump for ops::Timeval {
}
}

impl Dump for ops::Statx {
impl Dump for ops::StatResult {
fn dump(&self) -> String {
format!(
"[ uid={}, gid={}, mode={:#06o} ino={}, size={}, mtime={} ]",
Expand Down Expand Up @@ -323,10 +323,10 @@ impl Dump for ops::AccessOp {
impl Dump for ops::StatOp {
fn dump(&self) -> String {
format!(
"[ path={}, flags={}, statx_buf={}, errno={} ]",
"[ path={}, flags={}, stat_result={}, errno={} ]",
self.path.dump(),
self.flags,
self.statx_buf.dump(),
self.stat_result.dump(),
self.ferrno,
)
}
Expand Down
2 changes: 1 addition & 1 deletion probe_src/frontend/lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn should_prefix(name: &str) -> bool {
"ReadLinkOp",
"OpCode",
"Op",
"statx",
"StatResult",
"rusage",
"statx_timestamp",
"timespec",
Expand Down
47 changes: 20 additions & 27 deletions probe_src/frontend/python/probe_py/generated/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@ class StatxTimestamp:
nsec: int


@dataclass(init=True, frozen=True)
class Statx:
mask: int
blksize: int
attributes: int
nlink: int
uid: int
gid: int
mode: int
ino: int
size: int
blocks: int
attributes_mask: int
atime: StatxTimestamp
btime: StatxTimestamp
ctime: StatxTimestamp
mtime: StatxTimestamp
rdev_major: int
rdev_minor: int
dev_major: int
dev_minor: int
mnt_id: int
dio_mem_align: int
dio_offset_align: int


@dataclass(init=True, frozen=True)
class Timeval:
sec: int
Expand Down Expand Up @@ -159,12 +133,31 @@ class AccessOp:
ferrno: int


@dataclass(init=True, frozen=True)
class StatResult:
mask: int
nlink: int
uid: int
gid: int
mode: int
ino: int
size: int
blocks: int
blksize: int
atime: StatxTimestamp
btime: StatxTimestamp
ctime: StatxTimestamp
mtime: StatxTimestamp
dev_major: int
dev_minor: int


@dataclass(init=True, frozen=True)
class StatOp:
path: Path
flags: int
statx_buf: Statx
ferrno: int
stat_result: StatResult


@dataclass(init=True, frozen=True)
Expand Down
52 changes: 26 additions & 26 deletions probe_src/libprobe/generated/libc_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode)
int stat(const char *filename, struct stat *buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, 0), .flags = 0, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, 0), .flags = 0, .ferrno = 0, .stat_result = {0}}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -889,11 +889,11 @@ int stat(const char *filename, struct stat *buf)
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -904,7 +904,7 @@ int stat(const char *filename, struct stat *buf)
int stat64(const char *filename, struct stat64 *buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, 0), .flags = 0, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, 0), .flags = 0, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -915,11 +915,11 @@ int stat64(const char *filename, struct stat64 *buf)
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat64_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat64(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -930,7 +930,7 @@ int stat64(const char *filename, struct stat64 *buf)
int fstat(int filedes, struct stat *buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(filedes, "", AT_EMPTY_PATH), .flags = 0, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(filedes, "", AT_EMPTY_PATH), .flags = 0, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -941,11 +941,11 @@ int fstat(int filedes, struct stat *buf)
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -956,7 +956,7 @@ int fstat(int filedes, struct stat *buf)
int fstat64(int filedes, struct stat64 * restrict buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(filedes, "", AT_EMPTY_PATH), .flags = 0, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(filedes, "", AT_EMPTY_PATH), .flags = 0, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -967,11 +967,11 @@ int fstat64(int filedes, struct stat64 * restrict buf)
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat64_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat64(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -982,7 +982,7 @@ int fstat64(int filedes, struct stat64 * restrict buf)
int lstat(const char *filename, struct stat *buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW), .flags = AT_SYMLINK_NOFOLLOW, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW), .flags = AT_SYMLINK_NOFOLLOW, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -993,11 +993,11 @@ int lstat(const char *filename, struct stat *buf)
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -1008,7 +1008,7 @@ int lstat(const char *filename, struct stat *buf)
int lstat64(const char *filename, struct stat64 *buf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW), .flags = AT_SYMLINK_NOFOLLOW, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW), .flags = AT_SYMLINK_NOFOLLOW, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -1023,7 +1023,7 @@ int lstat64(const char *filename, struct stat64 *buf)
}
else
{
stat64_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat64(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -1034,7 +1034,7 @@ int lstat64(const char *filename, struct stat64 *buf)
int statx(int dirfd, const char * restrict pathname, int flags, unsigned int mask, struct statx * restrict statxbuf)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(dirfd, pathname, flags), .flags = flags, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(dirfd, pathname, flags), .flags = flags, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -1045,11 +1045,11 @@ int statx(int dirfd, const char * restrict pathname, int flags, unsigned int mas
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
op.data.stat.statx_buf = *statxbuf;
stat_result_from_statx(&op.data.stat.stat_result, statxbuf);
}
prov_log_record(op);
}
Expand All @@ -1060,7 +1060,7 @@ int statx(int dirfd, const char * restrict pathname, int flags, unsigned int mas
int fstatat(int dirfd, const char * restrict pathname, struct stat * restrict buf, int flags)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(dirfd, pathname, flags), .flags = flags, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(dirfd, pathname, flags), .flags = flags, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -1071,11 +1071,11 @@ int fstatat(int dirfd, const char * restrict pathname, struct stat * restrict bu
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand All @@ -1086,7 +1086,7 @@ int fstatat(int dirfd, const char * restrict pathname, struct stat * restrict bu
int fstatat64(int fd, const char * restrict file, struct stat64 * restrict buf, int flags)
{
maybe_init_thread();
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(fd, file, flags), .flags = flags, .statx_buf = {0}, .ferrno = 0}}, {0}, 0, 0};
struct Op op = {stat_op_code, {.stat = {.path = create_path_lazy(fd, file, flags), .flags = flags, .stat_result = {0}, .ferrno = 0}}, {0}, 0, 0};
if (likely(prov_log_is_enabled()))
{
prov_log_try(op);
Expand All @@ -1097,11 +1097,11 @@ int fstatat64(int fd, const char * restrict file, struct stat64 * restrict buf,
{
if (ret != 0)
{
op.data.readdir.ferrno = saved_errno;
op.data.stat.ferrno = saved_errno;
}
else
{
stat64_to_statx(&op.data.stat.statx_buf, buf);
stat_result_from_stat64(&op.data.stat.stat_result, buf);
}
prov_log_record(op);
}
Expand Down
Loading

0 comments on commit 1b50cdd

Please sign in to comment.