bidirectional ip reflection for listener address discovery
This commit is contained in:
@@ -838,13 +838,22 @@ pub fn checkDiskSpace(path: []const u8, required_bytes: u64) Error!void {
|
||||
|
||||
var stat: Statfs = undefined;
|
||||
|
||||
// Use extern fstatfs for both Linux and macOS
|
||||
const fstatfs_impl = struct {
|
||||
pub extern "c" fn fstatfs(fd: c_int, buf: *anyopaque) c_int;
|
||||
// Use fstatfs - requires libc on Linux, always available on macOS
|
||||
const result = if (builtin.os.tag == .macos or builtin.link_libc) blk: {
|
||||
const fstatfs_impl = struct {
|
||||
pub extern "c" fn fstatfs(fd: c_int, buf: *anyopaque) c_int;
|
||||
};
|
||||
break :blk fstatfs_impl.fstatfs(fd, &stat);
|
||||
} else if (builtin.os.tag == .linux) blk: {
|
||||
// Use Linux syscall directly when libc is not linked
|
||||
const linux = std.os.linux;
|
||||
const raw_result = linux.syscall2(.fstatfs, @as(usize, @bitCast(@as(isize, fd))), @intFromPtr(&stat));
|
||||
break :blk if (raw_result == 0) @as(c_int, 0) else @as(c_int, -1);
|
||||
} else blk: {
|
||||
// Skip check on unsupported platforms
|
||||
break :blk @as(c_int, -1);
|
||||
};
|
||||
|
||||
const result = fstatfs_impl.fstatfs(fd, &stat);
|
||||
|
||||
if (result != 0) {
|
||||
std.log.warn("Failed to get filesystem stats for {s}", .{dir_path});
|
||||
return; // Allow operation to proceed
|
||||
@@ -1104,13 +1113,8 @@ pub const FileWriter = struct {
|
||||
if (builtin.os.tag == .linux) {
|
||||
// FALLOC_FL_KEEP_SIZE = 0x01 - allocate without changing file size
|
||||
const FALLOC_FL_KEEP_SIZE = 0x01;
|
||||
const fd = file.handle;
|
||||
const result = std.os.linux.syscall(.fallocate, .{
|
||||
@as(usize, @intCast(fd)),
|
||||
@as(usize, FALLOC_FL_KEEP_SIZE),
|
||||
@as(usize, 0), // offset
|
||||
@as(usize, @intCast(size)),
|
||||
});
|
||||
const fd: i32 = @intCast(file.handle);
|
||||
const result = std.os.linux.fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, @intCast(size));
|
||||
if (result == 0) {
|
||||
std.log.debug("PERF: Pre-allocated {} MB with fallocate", .{size / (1024 * 1024)});
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user